简体   繁体   English

如何提高UglifyJsPlugin的性能

[英]How to improve performance of UglifyJsPlugin

Rebuilding a complex module takes about 25seconds without UglifyJsPlugin and just over 1 minute UglifyJsPlugin. 在没有UglifyJsPlugin的情况下,重建复杂的模块大约需要25秒,而在UglifyJsPlugin上只需花费1分钟以上。 On average a complete build spends 60-90% of the execution time in UglifyJsPlugin and I was wondering if I'm doing something wrong or this is just the way it is. 平均而言,完整的构建会在UglifyJsPlugin中花费60-90%的执行时间,而我想知道我是在做错什么,还是这就是事实。

Using: node 8.1.4 npm 5.2.0 webpack 3.2.0 uglifyjs-webpack-plugin 0.4.6 uglify-js: 2.8.29 使用:节点8.1.4 npm 5.2.0 webpack 3.2.0 uglifyjs-webpack-plugin 0.4.6 uglify-js:2.8.29

Options: 选项:

const UGLIFYJS_OPTIONS = {
    compress: {
        sequences: true,        // join consecutive simple statements using the comma operator
        properties: true,       // rewrite property access using the dot notation, for example foo["bar"] ? foo.bar
        dead_code: true,        // remove unreachable code
        drop_debugger: true,    // remove debugger; statements
        unsafe: false,          // apply "unsafe" transformations
        conditionals: true,     // apply optimizations for if-s and conditional expressions
        comparisons: true,      // apply certain optimizations to binary nodes
        evaluate: true,         // attempt to evaluate constant expressions
        booleans: true,         // various optimizations for boolean context
        loops: true,            // optimizations for do, while and for loops when we can statically determine the condition
        unused: true,           // drop unreferenced functions and variables
        hoist_funs: true,       // hoist function declarations
        hoist_vars: false,      // hoist var declarations (this is false by default because it seems to increase the size of the output in general)
        if_return: true,        // optimizations for if/return and if/continue
        join_vars: true,        // join consecutive var statements
        cascade: true,          // small optimization for sequences, transform x, x into x and x = something(), x into x = something()
        collapse_vars: false,   // Collapse single-use var and const definitions when possible.
        warnings: false,        // display warnings when dropping unreachable code or unused declarations etc.
        negate_iife: true,      // negate "Immediately-Called Function Expressions" where the return value is discarded, to avoid the parens that the code generator would insert.
        pure_getters: false,    // If you pass true for this, UglifyJS will assume that object property access (e.g. foo.bar or foo["bar"]) doesn't have any side effects.
        pure_funcs: null,       // You can pass an array of names and UglifyJS will assume that those functions do not produce side effects.
        drop_console: false,    // Pass true to discard calls to console.* functions.
        keep_fargs: true,       // Prevents the compressor from discarding unused function arguments. You need this for code which relies on Function.length.
        keep_fnames: false      // Pass true to prevent the compressor from mangling/discarding function names. Useful for code relying on Function.prototype.name.
    },
    sourceMap: true,
    output: {
        comments: function (node/*: any*/, comment/*: any*/) {
            if (comment.type === 'comment2') {
                // multiline comment
                return /@preserve/i.test(comment.value);
            }

            return false;
        }
    }
};

Disable compress and only enable mangle for very quick minification with acceptable file sizes. 禁用compress ,仅启用mangle以便以可接受的文件大小快速缩小文件。

See: https://github.com/mishoo/UglifyJS2#uglify-fast-minify-mode 参见: https : //github.com/mishoo/UglifyJS2#uglify-fast-minify-mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM