Skip to content

Commit e447f57

Browse files
chenjiahanCopilot
andauthored
docs(config): update Rule.type with more details (#11503)
* docs(config): update `Rule.type` with more details * Update website/docs/en/config/module.mdx Co-authored-by: Copilot <[email protected]> * fix --------- Co-authored-by: Copilot <[email protected]>
1 parent 88e51c3 commit e447f57

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

website/docs/en/blog/announcing-1-3.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ By utilizing modern JavaScript features supported by the target environment, Rsp
156156

157157
### Memory improvements
158158

159-
Rspack now defaults to using [mimalloc](https://github.com/microsoft/mimalloc) v3 on macOS. This mitigates some memory consumption issue on macOS during rebuilding. According to some community and internal projects, this would lift the RSS for rebuilding, based on the size of each project, varying from **10% to 85%**
159+
Rspack now defaults to using [mimalloc](https://github.com/microsoft/mimalloc) v3 on macOS. This mitigates some memory consumption issue on macOS during rebuilding. According to some community and internal projects, this would lift the RSS for rebuilding, based on the size of each project, varying from **10% to 85%**.
160160

161161
Rspack 1.3 also implemented an internal mechanism to clean the outdated cache: `maxGenerations`. This controls how many compilations would cache survive if it's not being used by the compiler. Rspack sets the default to `1`. This means that the cache will be purged if it's not being used in the next compilation.
162162

website/docs/en/config/experiments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ Please refer to [type reexports presence example](https://github.com/rspack-cont
833833
834834
By default, Rspack uses Watchpack to monitor file changes, which generally works well in most scenarios.
835835
However, in certain specific environments, issues may arise. For example, Watchpack may experience performance problems when there are a large number of file changes.
836-
More detail see: [Watchpack issue #233](https://github.com/webpack/watchpack/issues/223)
836+
More detail see: [Watchpack issue #233](https://github.com/webpack/watchpack/issues/223).
837837
838838
If you encounter performance issues with the default watcher, you can try enabling nativeWatcher.
839839

website/docs/en/config/module.mdx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ export default {
11791179
11801180
- **Type:** `string | ((pathData: PathData, assetInfo?: AssetInfo) => string)`
11811181
- **Default:** `undefined`
1182-
- **Supported Template string** checkout [`output.assetModuleFilename`](/config/output#outputassetmodulefilename)
1182+
- **Supported Template string:** checkout [`output.assetModuleFilename`](/config/output#outputassetmodulefilename)
11831183
11841184
Same as `output.assetModuleFilename`. Overrides `output.assetModuleFilename` and only works for `asset` and `asset/resource` module types.
11851185
@@ -2309,11 +2309,28 @@ There are two phases that all loaders enter one after the other:
23092309
23102310
### Rule.type
23112311
2312-
- **Type:** `'javascript/auto' | 'css' | 'css/module' | 'css/auto' | 'json' | 'asset' | 'asset/source' | 'asset/resource' | 'asset/inline'`
2312+
- **Type:**
2313+
2314+
```ts
2315+
type RuleType =
2316+
| 'asset'
2317+
| 'css'
2318+
| 'css/auto'
2319+
| 'css/module'
2320+
| 'javascript/auto'
2321+
| 'javascript/dynamic'
2322+
| 'javascript/esm'
2323+
| 'json';
2324+
```
23132325
23142326
Used to mark the type of the matching module, which affects how the module is handled by Rspack's built-in processing.
23152327
2316-
By default, Rspack will determine the type of the module based on the file extension. For example, `.js` and `.mjs` files will be treated as `javascript/auto` modules, and `.json` files will be treated as `json` modules.
2328+
By default, Rspack will determine the type of the module based on the file extension. For example:
2329+
2330+
- `.js` files will be treated as `javascript/auto` modules.
2331+
- `.mjs` files, as well as `.js` files in packages with `type="module"` in package.json, will be treated as `javascript/esm` modules.
2332+
- `.json` files will be treated as `json` modules.
2333+
- `.css` files will be treated as `css/auto` modules.
23172334
23182335
For example, if you want to load a `.json` file through a custom loader, you'd need to set the type to `javascript/auto` to bypass Rspack's built-in JSON importing.
23192336
@@ -2332,13 +2349,13 @@ export default {
23322349
};
23332350
```
23342351
2335-
All `type` options are as follows:
2352+
The meanings of all `type` options are as follows:
23362353
2337-
- `'javascript/auto'`: JavaScript modules, supported module systems: CommonJS, ES modules.
2338-
- `'javascript/esm'`JavaScript modules, treated as ES modules.
2339-
- `'javascript/dynamic'`JavaScript modules, treated as Script.
2354+
- `'javascript/auto'`: JavaScript modules. Rspack automatically determines the module type based on file content, providing the best compatibility.
2355+
- `'javascript/esm'`: JavaScript modules, treated as strict ES modules.
2356+
- `'javascript/dynamic'`: JavaScript modules, treated as Script.
23402357
- `'json'`: JSON data module, see [JSON](/guide/tech/json).
2341-
- `'css' | 'css/module' | 'css/auto'`: CSS module, see [Native CSS Support](/guide/tech/css#native-css-support).
2358+
- `'css' | 'css/module' | 'css/auto'`: CSS module, see [Built-in CSS support](/guide/tech/css#built-in-css-support).
23422359
- `'asset' | 'asset/source' | 'asset/resource' | 'asset/inline'`: Asset module, see [Asset Module](/guide/features/asset-module).
23432360
23442361
### Rule.layer

website/docs/en/guide/tech/css.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ document.getElementById('element').className = styles.red;
160160

161161
Rspack provides options to customize the parsing and generation of CSS Modules:
162162

163-
- [module.parser.css](/config/module#moduleparsercss)Configure the parsing of CSS Modules.
164-
- [module.generator.css](/config/module#modulegeneratorcss)Configure the generation of CSS Modules.
163+
- [module.parser.css](/config/module#moduleparsercss): Configure the parsing of CSS Modules.
164+
- [module.generator.css](/config/module#modulegeneratorcss): Configure the generation of CSS Modules.
165165

166166
:::
167167

website/docs/zh/config/module.mdx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,11 +2304,28 @@ export default {
23042304
23052305
### Rule.type
23062306
2307-
- **类型:** `'javascript/auto' | 'css' | 'css/module' | 'css/auto' | 'json' | 'asset' | 'asset/source' | 'asset/resource' | 'asset/inline'`
2307+
- **类型:**
2308+
2309+
```ts
2310+
type RuleType =
2311+
| 'asset'
2312+
| 'css'
2313+
| 'css/auto'
2314+
| 'css/module'
2315+
| 'javascript/auto'
2316+
| 'javascript/dynamic'
2317+
| 'javascript/esm'
2318+
| 'json';
2319+
```
23082320
23092321
用于标记匹配的模块的类型,这会影响 Rspack 内置对于该模块的处理方式。
23102322
2311-
默认情况下,Rspack 会根据文件扩展名来决定模块的类型。例如,`.js``.mjs` 文件会被当作 `javascript/auto` 模块处理,`.json` 文件会被当作 `json` 模块处理。
2323+
默认情况下,Rspack 会根据文件扩展名来决定模块的类型。例如:
2324+
2325+
- `.js` 文件会被当作 `javascript/auto` 模块处理。
2326+
- `.mjs` 文件,以及 package.json 中包含 `type="module"``.js` 文件会被当作 `javascript/esm` 模块处理。
2327+
- `.json` 文件会被当作 `json` 模块处理。
2328+
- `.css` 文件会被当作 `css/auto` 模块处理。
23122329
23132330
例如,如果你想通过一个自定义 Loader 加载 `.json` 文件,你需要将类型设置为 `javascript/auto` 以绕过 Rspack 内置的 JSON 导入。
23142331
@@ -2327,13 +2344,13 @@ export default {
23272344
};
23282345
```
23292346
2330-
所有 `type` 如下
2347+
所有 `type` 的含义如下
23312348
2332-
- `'javascript/auto'`:JavaScript 模块,支持的模块系统:CommonJS、ES modules
2349+
- `'javascript/auto'`:JavaScript 模块,Rspack 会根据文件内容自动判断模块类型,兼容性最佳
23332350
- `'javascript/esm'`:JavaScript 模块,当作严格 ES modules 处理。
23342351
- `'javascript/dynamic'`:JavaScript 模块,当作 Script 处理。
23352352
- `'json'`:JSON data 模块,参考 [JSON](/guide/tech/json)。
2336-
- `'css' | 'css/module' | 'css/auto'`:CSS 模块,参考 [原生 CSS 支持](/guide/tech/css#原生-css-支持)。
2353+
- `'css' | 'css/module' | 'css/auto'`:CSS 模块,参考 [内置 CSS 支持](/guide/tech/css#内置-css-支持)。
23372354
- `'asset' | 'asset/source' | 'asset/resource' | 'asset/inline'`:资源模块,参考 [资源模块](/guide/features/asset-module)。
23382355
23392356
### Rule.layer

0 commit comments

Comments
 (0)