@@ -6,27 +6,27 @@ repo: https://github.com/webpack-contrib/thread-loader
6
6
---
7
7
Runs the following loaders in a worker pool.
8
8
9
- ## Install {#install}
9
+ ## 安装 {#install}
10
10
11
11
``` bash
12
12
npm install --save-dev thread-loader
13
13
```
14
14
15
- ## Usage {#usage}
15
+ ## 用法 {#usage}
16
16
17
- Put this loader in front of other loaders. The following loaders run in a worker pool.
17
+ 使用时,需将此 loader 放置在其他 loader 之前。放置在此 loader 之后的 loader 会在一个独立的 worker 池中运行。
18
18
19
- Loaders running in a worker pool are limited. Examples:
19
+ 在 worker 池中运行的 loader 是受到限制的。例如:
20
20
21
- * Loaders cannot emit files.
22
- * Loaders cannot use custom loader API (i. e. by plugins).
23
- * Loaders cannot access the webpack options.
21
+ * 这些 loader 不能生成新的文件。
22
+ * 这些 loader 不能使用自定义的 loader API(也就是说,不能通过插件来自定义)。
23
+ * 这些 loader 无法获取 webpack 的配置。
24
24
25
- Each worker is a separate node.js process, which has an overhead of ~ 600ms. There is also an overhead of inter-process communication.
25
+ 每个 worker 都是一个独立的 node.js 进程,其开销大约为 600ms 左右。同时会限制跨进程的数据交换。
26
26
27
- Use this loader only for expensive operations!
27
+ 请仅在耗时的操作中使用此 loader!
28
28
29
- ## Examples {#examples}
29
+ ## 示例 {#examples}
30
30
31
31
** webpack.config.js**
32
32
@@ -39,7 +39,7 @@ module.exports = {
39
39
include: path .resolve (" src" ),
40
40
use: [
41
41
" thread-loader" ,
42
- // your expensive loader (e.g babel-loader)
42
+ // 耗时的 loader (例如 babel-loader)
43
43
]
44
44
}
45
45
]
@@ -53,58 +53,58 @@ module.exports = {
53
53
use: [
54
54
{
55
55
loader: " thread-loader" ,
56
- // loaders with equal options will share worker pools
56
+ // 有同样配置的 loader 会共享一个 worker 池
57
57
options: {
58
- // the number of spawned workers, defaults to (number of cpus - 1) or
59
- // fallback to 1 when require('os').cpus() is undefined
58
+ // 产生的 worker 的数量,默认是 (cpu 核心数 - 1),或者,
59
+ // 在 require('os').cpus() 是 undefined 时回退至 1
60
60
workers: 2 ,
61
61
62
- // number of jobs a worker processes in parallel
63
- // defaults to 20
62
+ // 一个 worker 进程中并行执行工作的数量
63
+ // 默认为 20
64
64
workerParallelJobs: 50 ,
65
65
66
- // additional node.js arguments
66
+ // 额外的 node.js 参数
67
67
workerNodeArgs: [' --max-old-space-size=1024' ],
68
68
69
- // Allow to respawn a dead worker pool
70
- // respawning slows down the entire compilation
71
- // and should be set to false for development
69
+ // 允许重新生成一个僵死的 work 池
70
+ // 这个过程会降低整体编译速度
71
+ // 并且开发环境应该设置为 false
72
72
poolRespawn: false ,
73
73
74
- // timeout for killing the worker processes when idle
75
- // defaults to 500 (ms)
76
- // can be set to Infinity for watching builds to keep workers alive
74
+ // 闲置时定时删除 worker 进程
75
+ // 默认为 500(ms)
76
+ // 可以设置为无穷大,这样在监视模式(--watch)下可以保持 worker 持续存在
77
77
poolTimeout: 2000 ,
78
78
79
- // number of jobs the poll distributes to the workers
80
- // defaults to 200
81
- // decrease of less efficient but more fair distribution
79
+ // 池分配给 worker 的工作数量
80
+ // 默认为 200
81
+ // 降低这个数值会降低总体的效率,但是会提升工作分布更均一
82
82
poolParallelJobs: 50 ,
83
83
84
- // name of the pool
85
- // can be used to create different pools with elsewise identical options
84
+ // 池的名称
85
+ // 可以修改名称来创建其余选项都一样的池
86
86
name: " my-pool"
87
87
}
88
88
},
89
- // your expensive loader (e.g babel-loader)
89
+ // 耗时的 loader (例如 babel-loader)
90
90
]
91
91
```
92
92
93
- ** prewarming **
93
+ ** 预警 **
94
94
95
- To prevent the high delay when booting workers it possible to warmup the worker pool.
95
+ 可以通过预警 worker 池来防止启动 worker 时的高延时。
96
96
97
- This boots the max number of workers in the pool and loads specified modules into the node.js module cache.
97
+ 这会启动池内最大数量的 worker 并把指定的模块加载到 node.js 的模块缓存中。
98
98
99
99
``` js
100
100
const threadLoader = require (' thread-loader' );
101
101
102
102
threadLoader .warmup ({
103
- // pool options, like passed to loader options
104
- // must match loader options to boot the correct pool
103
+ // 池选项,例如传递给 loader 选项
104
+ // 必须匹配 loader 选项才能启动正确的池
105
105
}, [
106
- // modules to load
107
- // can be any module, i. e.
106
+ // 加载模块
107
+ // 可以是任意模块,例如
108
108
' babel-loader' ,
109
109
' babel-preset-es2015' ,
110
110
' sass-loader' ,
0 commit comments