可选方案

  1. parallel-webpack (社区推出) —3的用的多一点
  2. HappyPack
  3. thread-loader (推荐)

thread-loader

  1. use:[
  2. // 开启多进程打包
  3. // 进程启动需要600ms左右
  4. {
  5. loader:'thread-load',
  6. options:{
  7. workers:2
  8. }
  9. }
  10. ]

多进程压缩

可选方案

  1. parallel-uglify-plugin插件
  2. uglifyjs-webpack-plugin插件 (不支持es6)
  3. terser-webpack-plugin 开启parallel参数

parallel-uglify-plugin

  1. const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
  2. module.exports = {
  3. plugins:{
  4. new ParallerUglifyPlugin({
  5. uglifyJs:{
  6. output:{
  7. beautify:false,
  8. comments:false
  9. },
  10. compress:{
  11. warning:false,
  12. drop_console:true,
  13. collapase_vars:true,
  14. reduce_vars:true
  15. }
  16. }
  17. })
  18. }
  19. }

terser-webpack-plugin

  1. const TerserPlugin = require('terser-webpack-plugin')
  2. modules.exports = {
  3. optimization:{
  4. minimizer:[
  5. new TerserPlugin({
  6. parallel:4
  7. })
  8. ]
  9. }
  10. }