使用 ng build --prod 删除所有评论和 console.logs,可能吗? [英] Stripping all comments and console.logs with ng build --prod, possible?

查看:24
本文介绍了使用 ng build --prod 删除所有评论和 console.logs,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MEAN、Angular 2、Node/Express、Angular-CLI 和 ng build --prod 来构建我的应用程序,我在我的应用程序中使用了大量注释掉的一次性代码和十亿个调试 console.log 语句.有没有办法让构建过程在构建时删除所有注释和 console.log 语句?手动操作的想法很可怕!

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!

推荐答案

我有一个简单的修复.把这段代码放在main.ts

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

这篇关于使用 ng build --prod 删除所有评论和 console.logs,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆