//模块happypack可以时间多线程(进程)来打包
//安装:npm install happypack
const happypack = require('happypack');

在配置文件webpack.config.js文件中,以前的加载js、css文件的使用方法如下:

module:{
    rules:[
        {test:/\.js$/,
         use:{
                loader:'babel-loader',
                options:{
                    presets:[
                        //解析ES6和react语法
                        '@babel/preset-env',
                        '@babel/preset-react'
                    ]
                } 
            }
        }
     },
        {
            test:/\.css$/,
            use:['style-loader','css-loader']
        }
    ]
 }

使用happypack后如下:

module:{
    rules:[
            {test:/\.js$/,
             use:'happypack/loader?id=js'
            },
        {
            test:/\.css$/,
            use:'happypack/loader?id=css'
        }
    ]
    },
    plugins: [
        new happypack({
            id:'css',
            use:['style-loader','css-loader']
        }),
        new happypack({
            id:'js',
            use:[{
                loader:'babel-loader',
                options:{
                    presets:[
                        //解析ES6和react语法
                        '@babel/preset-env',
                        '@babel/preset-react'
                    ]
                } 
            }]
        })
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-02-19
猜你喜欢
  • 2021-12-04
  • 2022-01-25
  • 2021-09-21
  • 2021-09-05
  • 2021-08-17
  • 2021-06-27
  • 2021-08-12
相关资源
相似解决方案