webpack 打包性能优化
2024-10-19 05:03:00
webpack 打包性能优化
开启多线程打包 thread-loader
https://www.npmjs.com/package/thread-loader
https://github.com/webpack-contrib/thread-loader
module.exports = {
module: {
rules: [
{
test: /\.js$/,
include: path.resolve('src'),
use: [
'thread-loader',
// your expensive loader (e.g babel-loader)
],
},
],
},
};
use: [
{
loader: 'thread-loader',
// loaders with equal options will share worker pools
options: {
// the number of spawned workers, defaults to (number of cpus - 1) or
// fallback to 1 when require('os').cpus() is undefined
workers: 2,
// number of jobs a worker processes in parallel
// defaults to 20
workerParallelJobs: 50,
// additional node.js arguments
workerNodeArgs: ['--max-old-space-size=1024'],
// Allow to respawn a dead worker pool
// respawning slows down the entire compilation
// and should be set to false for development
poolRespawn: false,
// timeout for killing the worker processes when idle
// defaults to 500 (ms)
// can be set to Infinity for watching builds to keep workers alive
poolTimeout: 2000,
// number of jobs the poll distributes to the workers
// defaults to 200
// decrease of less efficient but more fair distribution
poolParallelJobs: 50,
// name of the pool
// can be used to create different pools with elsewise identical options
name: 'my-pool',
},
},
// your expensive loader (e.g babel-loader)
];
prewarming 预热
const threadLoader = require('thread-loader');
threadLoader.warmup(
{
// pool options, like passed to loader options
// must match loader options to boot the correct pool
},
[
// modules to load
// can be any module, i. e.
'babel-loader',
'babel-preset-es2015',
'sass-loader',
]
);
为防止启动工作程序时出现高延迟,可以预热工作程序池。
这将引导池中的最大工作程序数量,并将指定的模块加载到node.js模块高速缓存中。
refs
shit 翻译
https://webpack.docschina.org/loaders/thread-loader/
Lerna
https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=Lerna
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
最新文章
- Webform 文件上传、 C#加图片水印 、 图片验证码
- 【VB6】VB6实现拖拽
- App开发流程之使用分类(Category)和忽略编译警告(Warning)
- View和ViewImage设置图片
- [问题2015S12] 复旦高等代数 II(14级)每周一题(第十三教学周)
- js中Dom对象的position属性
- python3 入门 (三) 函数与lambda表达式、闭包
- webservice发布在外网上的在system.web中加入这个就好使了
- DBA_在Linux上安装Oracle Database11g数据库(案例)
- 从浏览器的console获取angularjs的scope
- 配置并学习微信JS-SDK(1)
- 数据库管理工具神器-DataGrip,可同时管理多个主流数据库[SQL Server,MySQL,Oracle等]连接
- [M$]重装或更换主板后提示“由于指定产品密钥激活次数“ office 2016
- vue——router
- 绑定到外部验证服务LDAP、配置 autofs
- [AT2384] [agc015_f] Kenus the Ancient Greek
- 不平衡分类学习方法 --Imbalaced_learn
- Linux可以明文传输密码的工具sshpass
- 【微信小程序】微信小程序wx.previewImage预览图片
- 转!! 关于jsp编码设置 <;%@ page language=";java"; contentType=";text/html; charset=utf-8"; pageEncoding=";utf-8";%>;