Skip to content

Commit 667b3ca

Browse files
weiyuan0609QC-L
andauthored
docs(cn): translate src/content/loaders/thread-loader.md (#818)
Co-authored-by: QiChang Li <[email protected]>
1 parent 488faea commit 667b3ca

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/content/loaders/thread-loader.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ repo: https://github.com/webpack-contrib/thread-loader
66
---
77
Runs the following loaders in a worker pool.
88

9-
## Install {#install}
9+
## 安装 {#install}
1010

1111
```bash
1212
npm install --save-dev thread-loader
1313
```
1414

15-
## Usage {#usage}
15+
## 用法 {#usage}
1616

17-
Put this loader in front of other loaders. The following loaders run in a worker pool.
17+
使用时,需将此 loader 放置在其他 loader 之前。放置在此 loader 之后的 loader 会在一个独立的 worker 池中运行。
1818

19-
Loaders running in a worker pool are limited. Examples:
19+
worker 池中运行的 loader 是受到限制的。例如:
2020

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 的配置。
2424

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 左右。同时会限制跨进程的数据交换。
2626

27-
Use this loader only for expensive operations!
27+
请仅在耗时的操作中使用此 loader
2828

29-
## Examples {#examples}
29+
## 示例 {#examples}
3030

3131
**webpack.config.js**
3232

@@ -39,7 +39,7 @@ module.exports = {
3939
include: path.resolve("src"),
4040
use: [
4141
"thread-loader",
42-
// your expensive loader (e.g babel-loader)
42+
// 耗时的 loader (例如 babel-loader
4343
]
4444
}
4545
]
@@ -53,58 +53,58 @@ module.exports = {
5353
use: [
5454
{
5555
loader: "thread-loader",
56-
// loaders with equal options will share worker pools
56+
// 有同样配置的 loader 会共享一个 worker
5757
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
6060
workers: 2,
6161

62-
// number of jobs a worker processes in parallel
63-
// defaults to 20
62+
// 一个 worker 进程中并行执行工作的数量
63+
// 默认为 20
6464
workerParallelJobs: 50,
6565

66-
// additional node.js arguments
66+
// 额外的 node.js 参数
6767
workerNodeArgs: ['--max-old-space-size=1024'],
6868

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
7272
poolRespawn: false,
7373

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 持续存在
7777
poolTimeout: 2000,
7878

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+
// 降低这个数值会降低总体的效率,但是会提升工作分布更均一
8282
poolParallelJobs: 50,
8383

84-
// name of the pool
85-
// can be used to create different pools with elsewise identical options
84+
// 池的名称
85+
// 可以修改名称来创建其余选项都一样的池
8686
name: "my-pool"
8787
}
8888
},
89-
// your expensive loader (e.g babel-loader)
89+
// 耗时的 loader (例如 babel-loader
9090
]
9191
```
9292

93-
**prewarming**
93+
**预警**
9494

95-
To prevent the high delay when booting workers it possible to warmup the worker pool.
95+
可以通过预警 worker 池来防止启动 worker 时的高延时。
9696

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 的模块缓存中。
9898

9999
``` js
100100
const threadLoader = require('thread-loader');
101101

102102
threadLoader.warmup({
103-
// pool options, like passed to loader options
104-
// must match loader options to boot the correct pool
103+
// 池选项,例如传递给 loader 选项
104+
// 必须匹配 loader 选项才能启动正确的池
105105
}, [
106-
// modules to load
107-
// can be any module, i. e.
106+
// 加载模块
107+
// 可以是任意模块,例如
108108
'babel-loader',
109109
'babel-preset-es2015',
110110
'sass-loader',

0 commit comments

Comments
 (0)