Skip to content

Commit a74fcab

Browse files
authored
docs(loader): update Rule.use.parallel to include maxWorkers option (#12322)
* docs(loader): update Rule.use.parallel to include maxWorkers option * Apply suggestion from @chenjiahan * docs: fix
1 parent 91e6be8 commit a74fcab

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

packages/rspack/src/config/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,15 @@ export type RuleSetLoaderWithOptions = {
882882

883883
loader: RuleSetLoader;
884884

885+
/**
886+
* Controls whether a given loader should run in worker threads for parallel execution. Loaders marked
887+
* with `parallel` are scheduled across multiple threads, reducing pressure on the main thread and improving
888+
* overall build performance.
889+
* - When set to `true`, the loader runs in a worker. Rspack automatically selects an appropriate number of
890+
* worker threads.
891+
* - When set to `{ maxWorkers }`, you can explicitly define the maximum number of workers to use.
892+
* - When set to `false` or omitted, the loader runs on the main thread.
893+
*/
885894
parallel?: boolean | { maxWorkers?: number };
886895

887896
options?: RuleSetLoaderOptions;

website/docs/en/config/module.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,13 @@ export default {
26462646
- **Type**: `boolean`
26472647
- **Default:** `false`
26482648
2649-
In version 1.3.1, the `Rule.use.parallel` configuration option was introduced. When enabled for corresponding loaders and `experiments.parallelLoader = true` is configured, the respective loaders will be executed in worker threads:
2649+
Controls whether a given loader should run in worker threads for parallel execution. Loaders marked with `parallel` are scheduled across multiple threads, reducing pressure on the main thread and improving overall build performance.
2650+
2651+
- When set to `true`, the loader runs in a worker. Rspack automatically selects an appropriate number of worker threads.
2652+
- When set to `{ maxWorkers }`, you can explicitly define the maximum number of workers to use.
2653+
- When set to `false` or omitted, the loader runs on the main thread.
2654+
2655+
For example, enabling parallel execution for `less-loader`:
26502656
26512657
```js title="rspack.config.mjs"
26522658
export default {
@@ -2672,13 +2678,13 @@ export default {
26722678
};
26732679
```
26742680
2675-
When multiple loaders in the current `Rule` are configured with `Rule.use.parallel = true`, Rspack will execute all loader tasks in the same worker until it encounters the next loader without the `parallel` flag or a Rust `builtin:` loader. This approach enhances loader parallel performance.
2681+
When multiple loaders within the same rule have `parallel` enabled, Rspack executes them sequentially inside the same worker until it encounters a non-parallel loader or a Rust-implemented builtin loader. This preserves loader order while maximizing parallel efficiency.
26762682
2677-
:::warning
2683+
:::tip
26782684
2679-
- This configuration only takes effect when [experiments.parallelLoader](/config/experiments#experimentsparallelloader) is enabled.
2680-
- The loader configuration must comply with the [HTML structured clone algorithm](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist), otherwise transmission will fail.
2681-
- Currently, Rspack does not support most of the methods on `LoaderContext._compilation`, `LoaderContext._compiler`, `LoaderContext._module`.
2685+
- This feature is experimental. It only takes effect when [experiments.parallelLoader](/config/experiments#experimentsparallelloader) is enabled.
2686+
- The loader options must comply with the [HTML structured clone algorithm](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist), otherwise transmission will fail.
2687+
- In worker mode, most methods on `LoaderContext._compilation`, `LoaderContext._compiler`, `LoaderContext._module` are not supported.
26822688
26832689
:::
26842690

website/docs/zh/config/module.mdx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,10 +2640,16 @@ export default {
26402640
26412641
<ApiMeta addedVersion="1.3.1" />
26422642
2643-
- **类型**: `boolean`
2643+
- **类型**: `boolean | { maxWorkers?: number }`
26442644
- **默认值:** `false`
26452645
2646-
在 1.3.1 版本中支持了 `Rule.use.parallel` 配置项,当对对应 loader 开启并配置 `experiments.parallelLoader = true` 后,对应的 loader 会被发送到 worker threads 执行:
2646+
用于将指定 loader 放入 worker threads 中并行执行,被标记为 `parallel` 的 loader 会通过多线程调度运行,从而减少主线程的负担并提升构建性能。
2647+
2648+
- 设置为 `true` 时,loader 会在 worker 中执行,并由 Rspack 自动选择合适的线程数量。
2649+
- 设置为 `{ maxWorkers }` 时,可以手动控制最大 worker 的数量。
2650+
- 设置为 `false` 或省略时,该 loader 默认会在主线程中执行。
2651+
2652+
例如,将 `less-loader` 配置为并行执行:
26472653
26482654
```js title="rspack.config.mjs"
26492655
export default {
@@ -2669,13 +2675,13 @@ export default {
26692675
};
26702676
```
26712677
2672-
对于当前 `Rule` 中有多个 loader 同时配置了 `Rule.use.parallel = true`,rspack 会在同个 worker 中执行所有 loader 任务,直到下一个没有标记 `parallel` 的 loader 或下一个 loader 为一个 Rust `builtin:` loader。这样做可以提升 loader 的并行性能
2678+
当同一条 Rule 下有多个 loader 开启了 `parallel` 选项,Rspack 会在同一个 worker 中按顺序依次运行这些 loader,直到遇到未启用 parallel 的 loader Rust 实现的 builtin loader。这样可以在保证 loader 顺序的前提下最大化并行效率
26732679
2674-
:::warning
2680+
:::tip
26752681
2676-
- 只有开启 [experiments.parallelLoader](/config/experiments#experimentsparallelloader) 时该配置才会生效。
2677-
- loader 的配置需要满足 [HTML structured clone algorithm](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist),否则会发送失败。
2678-
- 目前 Rspack 不支持大多数 `LoaderContext._compilation`, `LoaderContext._compiler`, `LoaderContext._module` 上的方法
2682+
- 由于当前功能是实验性特性,只有开启 [experiments.parallelLoader](/config/experiments#experimentsparallelloader) 时该配置才会生效。
2683+
- loader 的选项需要满足 [HTML structured clone algorithm](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist),否则会发送失败。
2684+
- 目前 loader 在 worker 中不支持 `LoaderContext._compilation`, `LoaderContext._compiler`, `LoaderContext._module` 上的大多数方法
26792685
26802686
:::
26812687

0 commit comments

Comments
 (0)