I am using MEAN, Angular 2, Node/Express, Angular-CLI and ng build --prod to build my app and I have a travesty of commented out throwaway code and a billion debugging conso
Simply add this window.console.log = function(){};
to `
if (environment.production) {
enableProdMode();
}`
I have simple fix. Put this code in main.ts
if(env === 'prod') { // assuming you have env variable configured
// check if window exists, if you render backend window will not be available
if(window){
window.console.log = function(){};
}
}
You can use ng lint
with --fix
flag and no-console
rule in tslint configuration file. And hook it to your build call in your package file.
eg.:
...
"prebuild": "ng lint --fix",
"build": "ng build -prod",
...
and build the app
npm run build
ref: https://github.com/angular/angular-cli/wiki/lint