Skip to content

Commit 9589b71

Browse files
committed
docs: add default module definition systems
1 parent f0c97fd commit 9589b71

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

website/docs/en/config/lib/format.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,32 @@ See [Output Format](/guide/basic/output-format) and [Module Federation](/guide/a
1313
The `umd` format only works when [bundle](/config/lib/bundle) is set to `true`.
1414

1515
:::
16+
17+
## Module definition systems
18+
19+
In different output formats, Rslib uses the following default module definition systems:
20+
21+
- `esm`[modern-module](https://rspack.dev/config/output#type-modern-module)
22+
- `cjs`[commonjs-static](https://rspack.dev/config/output#type-commonjs-static)
23+
- `umd`[umd](https://rspack.dev/config/output#type-umd)
24+
25+
If you want to use a different module definition system, you can configure the [tools.rspack.output.library.type](https://rspack.dev/config/output#outputlibrarytype) option. Below is an example that sets the module definition system for the `cjs` format to `commonjs`:
26+
27+
```ts title="rslib.config.ts"
28+
export default {
29+
lib: [
30+
{
31+
format: 'cjs',
32+
tools: {
33+
rspack: {
34+
output: {
35+
library: {
36+
type: 'commonjs',
37+
},
38+
},
39+
},
40+
},
41+
},
42+
],
43+
};
44+
```

website/docs/zh/config/lib/format.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,32 @@
1111
::: note
1212
`umd` 格式仅在 [bundle](/config/lib/bundle) 设置为 `true` 时有效。
1313
:::
14+
15+
## 模块定义系统
16+
17+
在不同的产物格式下,Rslib 默认使用的模块定义系统如下:
18+
19+
- `esm`[modern-module](https://rspack.dev/zh/config/output#type-modern-module)
20+
- `cjs`[commonjs-static](https://rspack.dev/zh/config/output#type-commonjs-static)
21+
- `umd`[umd](https://rspack.dev/zh/config/output#type-umd)
22+
23+
如果你想要使用其他的模块定义系统,可以配置 [tools.rspack.output.library.type](https://rspack.dev/zh/config/output#outputlibrarytype) 选项。以下是一个示例,将 `cjs` 产物的模块定义系统设置为 `commonjs`
24+
25+
```ts title="rslib.config.ts"
26+
export default {
27+
lib: [
28+
{
29+
format: 'cjs',
30+
tools: {
31+
rspack: {
32+
output: {
33+
library: {
34+
type: 'commonjs',
35+
},
36+
},
37+
},
38+
},
39+
},
40+
],
41+
};
42+
```

0 commit comments

Comments
 (0)