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

查看:80
本文介绍了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弹出和ng弹出--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将保留类名.角度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天全站免登陆