Albin
Albin

Reputation: 63

How to hide console.log on production in angular 9+

I have tried the code

if (window) {
    window.console.log = () => { };
  }

in main.ts which hides the console on production up to angular 8 versions. But in angular 9+ does not hide the console in production.Any solutions

Upvotes: 3

Views: 4772

Answers (1)

Salahuddin Ahmed
Salahuddin Ahmed

Reputation: 5650

May be following code would work for you!

put the following code in main.ts:

if (environment.production) {
  enableProdMode();
if(window){
  window.console.log=function(){};
 }
}

and/or put the following code in polyfill.ts:

if(!window.console) {
 var console = {
  log : function(){},
  warn : function(){},
  error : function(){},
  time : function(){},
  timeEnd : function(){}
 }
}

Upvotes: 3

Related Questions