多进程打包
npm i thread-loader -D
使用
- 一般为
babel-loader
使用
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'thread-loader',
options: {
workers: 2, // 进程数
},
},
{
loader: 'babel-loader',
/* CODE··· */
}
]
}
]
}
}
进程利弊(主要关注如何合理利用)
- 进程开启大概需要600ms
- 进程通信也需要花费时间
- 尽量给消耗工作时间比较长的对象进行使用,否则会影响正常速度