Skip to content

Commit b531d85

Browse files
authored
docs(config): improve module.defaultRules documentation (#12230)
* docs(config): improve module.defaultRules documentation * docs
1 parent 2f78a97 commit b531d85

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

website/docs/en/config/module.mdx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,44 @@ Used to decide how to handle different types of modules in a project.
1313

1414
## module.defaultRules
1515

16-
- **Type:** `Rule[]`
16+
- **Type:** `(Rule | Falsy)[]`
17+
18+
`defaultRules` configures the built-in module resolution and processing rules that Rspack enables by default. These rules are applied automatically to ensure that common resource types such as JavaScript, JSON, CSS, and Wasm can be correctly resolved and bundled.
1719

18-
An array of rules applied by default for modules.
20+
You can extend, override, or disable these default rules to gain finer control over the build behavior.
1921

20-
See [source code](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/config/defaults.ts#L381) for details.
22+
For example, extending the default rules:
2123

2224
```js title="rspack.config.mjs"
2325
export default {
2426
module: {
2527
defaultRules: [
26-
'...', // you can use "..." to reference those rules applied by webpack by default
28+
// Use "..." to reference Rspack’s default rules
29+
'...',
30+
// Add a custom rule
31+
{
32+
test: /\.foo$/,
33+
use: ['foo-loader'],
34+
},
2735
],
2836
},
2937
};
3038
```
3139

40+
If you want to remove all of Rspack's default rules, simply omit `"..."`:
41+
42+
```js title="rspack.config.mjs"
43+
export default {
44+
module: {
45+
defaultRules: [],
46+
},
47+
};
48+
```
49+
50+
:::tip
51+
See the [source code](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/config/defaults.ts#L453) for the full list of default rules.
52+
:::
53+
3254
## module.noParse
3355

3456
- **Type:** `string | string[] | RegExp | RegExp[] | ((request: string) => boolean)`

website/docs/zh/config/module.mdx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,42 @@ import WebpackLicense from '@components/WebpackLicense';
1515

1616
- **类型:** `(Rule | Falsy)[]`
1717

18-
应用于模块的默认规则
18+
`defaultRules` 用于配置 Rspack 在内部默认启用的模块解析与处理规则。这些规则是自动生效的,用于确保常见资源类型(如 JavaScript、JSON、CSS、Wasm 等)能够被正常解析和打包
1919

20-
详见[源代码](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/config/defaults.ts#L381)
20+
你可以通过该选项扩展、覆写或禁用默认规则,从而对构建行为进行更细粒度的控制。
21+
22+
例如,扩展默认规则:
2123

2224
```js title="rspack.config.mjs"
2325
export default {
2426
module: {
2527
defaultRules: [
26-
'...', // 使用 "..." 来引用 Rspack 默认规则
28+
// 你可以使用 "..." 来引用 Rspack 默认的规则
29+
'...',
30+
// 增加一个自定义规则
31+
{
32+
test: /\.foo$/,
33+
use: ['foo-loader'],
34+
},
2735
],
2836
},
2937
};
3038
```
3139

40+
如果你希望移除 Rspack 所有的默认规则,你可以省略 `"..."`
41+
42+
```js title="rspack.config.mjs"
43+
export default {
44+
module: {
45+
defaultRules: [],
46+
},
47+
};
48+
```
49+
50+
:::tip
51+
查看 [源代码](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/config/defaults.ts#L453) 了解所有的默认规则。
52+
:::
53+
3254
## module.noParse
3355

3456
- **类型:** `string | string[] | RegExp | RegExp[] | ((request: string) => boolean)`

0 commit comments

Comments
 (0)