Stripping all comments and console.logs with ng build --prod, possible?

前端 未结 3 682
时光取名叫无心
时光取名叫无心 2020-12-13 12:53

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 conso

相关标签:
3条回答
  • 2020-12-13 13:13

    Simply add this window.console.log = function(){}; to `

    if (environment.production) {
        enableProdMode();
    }`
    
    0 讨论(0)
  • 2020-12-13 13:15

    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(){};
       }
    }  
    
    0 讨论(0)
  • 2020-12-13 13:17

    You can use ng lint with --fix flag and no-console rule in tslint configuration file. And hook it to your build call in your package file.

    eg.: ... "prebuild": "ng lint --fix", "build": "ng build -prod", ...

    and build the app

    npm run build

    ref: https://github.com/angular/angular-cli/wiki/lint

    0 讨论(0)
提交回复
热议问题