方法一、使用自带插件UglifyJsPlugin
var path = require('path');
var webpack = require('webpack')//第一次使用插件时,别忘了这步
module.exports = {
entry: './app/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
};
方法2 为执行命令添加参数 -p
修改build脚本(package.json里)
-p shortcut for --optimize-minimize --define process.env.NODE_ENV="production" //压缩并将工作环境改为‘产品’
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
- "build": "webpack"
+ "build": "webpack -p"
},