You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 04:39:00