打包速度优化
Webpack 默认提供的 UglifyJS 插件,由于采用单线程压缩,速度颇慢 ;推荐采用 webpack-parallel-uglify-plugin 插件,其做法如下,
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false }, sourceMap: true})
替换如上自带的 UglifyJsPlugin 写法为如下配置即可:
var ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');new ParallelUglifyPlugin({ cacheDir: '.cache/', uglifyJS:{ output: { comments: false }, compress: { warnings: false } }})
去掉正式环境的console.log
在压缩插件里过滤掉即可,加后的代码如下:
new ParallelUglifyPlugin({ cacheDir: '.cache/', uglifyJS:{ output: { comments: false }, compress: { warnings: false, drop_console: true, pure_funcs: ['console.log'] } } })