Angular 8中执行ng build prod时如何移除所有代码注释
Angular 8 构建时移除全部代码注释操作方案
- 首先修正构建命令格式:你当前使用的
ng build prod为错误写法,Angular 8 官方标准生产构建命令为ng build --prod,该命令默认开启代码压缩、摇树优化逻辑,会自动移除普通业务代码注释,仅保留license类特殊注释。 - 若需要移除全部注释(包括license类注释),需修改项目根目录下的
angular.json配置文件,按如下路径找到对应配置节点:projects > 你的实际项目名称 > architect > build > configurations > production - 在production节点下添加/更新如下配置:
"optimization": true, "terserOptions": { "output": { "comments": false }, "compress": { "drop_console": true, "drop_debugger": true } }
- 配置修改完成后重新执行
ng build --prod命令,构建出的产物内所有JS、CSS代码注释都会被完全移除。
内容的提问来源于stack exchange,提问作者yihijes925
相关产品推荐
相关产品推荐

