且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular-cli:如何忽略类名被缩小

更新时间:2022-02-18 08:53:12

Angular cli 在内部使用 webpack 和 uglify.一种解决方案是通过导出 webpack 配置来更改 uglify 中的选项.你可以通过运行 ng eject 和 ng eject --prod

Angular cli uses webpack and uglify internally. One solution would be changing the options in uglify by exporting the webpack configuration. You can see the webpack files by running ng eject, and ng eject --prod

new UglifyJsPlugin({
      "mangle": false,
      "compress": {
        "screw_ie8": true,
        "warnings": false
      },
      "sourceMap": false
    }),

Mangle = false 将保留类名.angular cli 中缺少 webpack 选项是一大讨论 atm.

Mangle = false will preserve class names. The lack of options for webpack in angular cli is one big discussion atm.

您也可以像这样设置排除项:

You can alse set exclusions like this:

mangle: {
    except: ['foozah']
  }

注意:弹出后,您可以从 angular-cli.json 中删除弹出的 true 以再次执行或正常服务/构建.

Note: after ejecting you can remove ejected true from angular-cli.json to do it again or serve/build normally.

"project": {
    "name": "test",
    "ejected": true //remove
  },