DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Akiko IKEHARA
Akiko IKEHARA

Posted on

Remove console logs in production build (Angular 2.x)

Problem / Goal

For debugging, most of us often write console.log to enable us to analyze problems.Β 
But, it is might be dangerous because there is a risk of accidentally outputting confidential information (api key, password, etc).
Therefor, we don't want to output console.log in production.

Solution Overview

Override console.log method on a function that does nothing.
(There is also another way that use webpack settings.)

Concrete Steps

Override console.log method on a function that does nothing.

app/main.ts

if (environment.production) {
  window.console.log = () => {};
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Create an Account!

πŸ‘€ Just want to lurk?

That's fine, you can still create an account and turn on features like 🌚 dark mode.