Angular-cli:如何忽略类名被缩小 [英] Angular-cli : How to ignore class names from being minified

查看:23
本文介绍了Angular-cli:如何忽略类名被缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于应用程序,我们需要保持类名不被缩小,因为我们使用

For an application we need to keep the classname not minified because we use

var className = myObject.constructor.name;
export class myObject{ ... }

当我们跑步时

ng build -- pro

ng build -- pro

类名被缩小为随机名称.

the class name gets minified in a random name.

推荐答案

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
  },

这篇关于Angular-cli:如何忽略类名被缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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