这个答案之前完美地起到了作用:
https://dev59.com/hFgR5IYBdhLWcg3wqOxW#41041580
然而,自Webpack v4以来,它不再起作用。此后,它会抛出以下错误:
Error: webpack.optimize.UglifyJsPlugin已被删除,请使用config.optimization.minimize代替。
为使其在Webpack v4中正常工作,需要做什么?
我尝试了以下方法,但没有成功:
const uglifyJsPlugin = require('uglifyjs-webpack-plugin');
if (process.argv.indexOf('-p') !== -1) {
// compress and remove console statements. Only add this plugin in production
// as even if drop_console is set to false, other options may be set to true
config.plugins.push(new uglifyJsPlugin({
compress: {
'drop_console': true
}
}));
}