I am using MEAN, Angular 2, Node/Express, Angular-CLI and ng build --prod to build my app and I have a travesty of commented out throwaway code and a billion debugging console.log statements throughout my app. Is there a way to have the build process remove all comments and console.log statements when it builds? The thought of doing it manually is scary!
The ng build command is intentionally for building the apps and deploying the build artifacts. The command does not generate an output folder. The output folder is – dist/. The ng serve builds artifacts from memory instead for a faster development experience.
Angular CLI. By using Angular CLI it is very easy to build your production app by using ng build --prod, but you will notice that console. log statements are not deleted from production files.
ng build now uses the production configuration by default. You no longer need to pass the --prod option to the command.
I have simple fix. Put this code in main.ts
if(env === 'prod') { // assuming you have env variable configured // check if window exists, if you render backend window will not be available if(window){ window.console.log = function(){}; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With