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

Viewed 1579

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

1 Answers

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(){}
 }
}
Related