webpack --bundle.js压缩

1.控制npm版本,降版本至5.6.0

npm install -g [email protected]

2.下载 uglifyjs-webpack-plugin

npm i -D uglifyjs-webpack-plugin

3.在webpack.config.js中添加

const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
plugins: [
    new UglifyJSPlugin({
            parallel: 4,
            uglifyOptions: {
                output: {
                    comments: false,
                    beautify: false,
                },
                compress: {
                    warnings: false
                },
            },
            cache: true,
        }),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
]

 

你可能感兴趣的:(前端,js,组件)