Webpack打包成Product時需要自動把Warning跟log給移除。
可以在plugin加入參數即可,v4跟v2版本有很大的差異。
在此提供兩種版本的方式。
Webpack v4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// 需引入uglifyjs-webpack-plugin,這邊與v2就不一樣 const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); plugins: [ new UglifyJsPlugin({ sourceMap: true, uglifyOptions: { ie8: false, ecma: 8, parse: {}, mangle: true, output: { comments: false, beautify: false }, compress: true, warnings: false } }) ] |
Webpack v2
1 2 3 4 5 6 7 8 9 10 |
// v2 版本直接使用webpack.optimize即可 plugins: [ new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false, // remove 警告 drop_console: true // 移除console.log } }) ] |
Reference
https://blog.csdn.net/xiaoguang44/article/details/89555376
https://blog.csdn.net/xiasohuai/article/details/88527483
https://segmentfault.com/a/1190000015032321