1

I'm outputting a lot a internal info through extensive use of console.log(). Is there a way to change the .log() command for my --prod builds in Angular?

FiringBlanks
  • 1,998
  • 4
  • 32
  • 48
  • you can comment all the unnecessary logs using find & replace functionality in your code editor – Seba Cherian Apr 10 '19 at 05:39
  • If you have using tslint, you could have set the `no-console` rule, which would reminded you to remove the excessive console.logs – wentjun Apr 10 '19 at 05:51
  • Possible duplicate of [remove console.logs with Webpack & Uglify](https://stackoverflow.com/questions/41040266/remove-console-logs-with-webpack-uglify). In short: Use `TerserPlugin` with the `drop_console` option set to true – Daniel Hilgarth Apr 10 '19 at 05:52

2 Answers2

4

Building off of Yash Rami's answer, I found that I needed to use window.console.log() in main.ts.

if(environment.production){
    window.console.log = function() {}
    enableProdMode();
}
FiringBlanks
  • 1,998
  • 4
  • 32
  • 48
1

you need to write this in main.ts. I hope it helps you out

      import { enableProdMode } from '@angular/core';
      import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
      import { AppModule } from './app/app.module';
      import { environment } from './environments/environment';

      if (environment.production) {
        console.log = function() {}   // this will be disable all the logs in production mode 
        enableProdMode();
      }

      platformBrowserDynamic().bootstrapModule(AppModule)
      .catch(err => console.log(err));
Yash Rami
  • 2,276
  • 1
  • 10
  • 16