ValidationError:UglifyJS插件无效选项

时间:2019-10-18 05:51:18

标签: javascript webpack

const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
    optimization: {
        minimizer: [new UglifyJsPlugin()],
    }
    ///
    plugins : [
        new webpack.optimize.UglifyJsPlugin({
            mangle: true,
            compress: {
                warnings: false, // Suppress uglification warnings
                pure_getters: true,
                unsafe: true,
                unsafe_comps: true,
                screw_ie8: true
            },
            output: {
                comments: false,
            },
            exclude: [/\.min\.js$/gi] // skip pre-minified libs
        }),
// ...

我的捆绑包大小为8.6 Mb。我需要将其大小调整为1-3 Mb。如果我的插件给我一个错误Unresolved type UglifyJsPlugin,我该怎么办?

Erro message

1 个答案:

答案 0 :(得分:0)

您不应将其用作插件:plugins : [new webpack.optimize.UglifyJsPlugin({

您还使用了错误的结构。根据{{​​3}},您的选择应如下所示:

module.exports = {
    optimization: {
        minimizer: [
            new UglifyJsPlugin({
                uglifyOptions: {
                    mangle: true,
                    warnings: false,
                    compress: {
                        pure_getters: true,
                        unsafe: true,
                        unsafe_comps: true,
                        //screw_ie8: true, // no such option in uglify
                    },
                    output: {
                        comments: false,
                    },
                },
                exclude: [/\.min\.js$/gi] // skip pre-minified libs
            }),
        ],
    },
};

UglifyJS Webpack Plugin docs