Angular – Clear all your console logs in production build with just a few lines of code.

When you were developing an application, you probably insert a lot of console.log statements in your code everywhere. Sometimes you display information that your users are not supposed to see but you think that most of the time, most users will not press F12 so you think you’re good. Not only it is a bad practice, you are also being lazy.
I will show you a trick where you can retain all your console log statements when in development mode and clear all of it when in production mode.
Go to your main.ts file and add this:

Now you have a clean console log when you build your app for production

Note:

Just in case you don’t know how to build for production, here’s the command

 

Leave a Reply

Your email address will not be published. Required fields are marked *