使用 UglifyJS 压缩文件。
使用 UglifyJS 优化 JavaScript 文件
如果您以前还没有使用 Grunt,请务必查看 入门指南,该指南介绍了如何创建 Gruntfile,以及如何安装和使用 Grunt 插件。一旦熟悉了这个过程,您可以使用以下命令安装此插件:
npm install grunt-contrib-uglify --save-dev安装插件后,可以在 Gruntfile 中使用以下 JavaScript 行来启用它:
grunt.loadNpmTasks('grunt-contrib-uglify');使用 grunt uglify 命令运行此任务。
任务目标、文件和选项可以根据 grunt 配置任务 指南指定。
| 选项 | 替换 |
|---|---|
| ASCIIOnly | output.ascii_only |
| enclose | — |
| exportAll | — |
| expression | parse.expression |
| indentLevel | output.indent_level |
| mangleProperties | mangle.properties |
| maxLineLen | output.max_line_len |
| preserveComments | output.comments |
| quoteStyle | output.quote_style |
| screwIE8 | !ie8 |
| sourceMapIncludeSources | sourceMap.includeSources |
| sourceMapRoot | sourceMap.root |
| sourceMapUrl | sourceMap.url |
类型: Boolean Object
默认值: {}
使用默认选项打开或关闭混淆。如果指定了 Object,则它会直接传递给 ast.mangle_names() 和 ast.compute_char_frequency()(模仿命令行行为)。查看所有选项。
暂无开放 Issues,或尚未同步最近议题。