Skip to content

Commit 9dc4a48

Browse files
authored
chore: add jsDoc for more configurations (#657)
1 parent 91d3672 commit 9dc4a48

File tree

8 files changed

+123
-42
lines changed

8 files changed

+123
-42
lines changed

packages/core/src/types/config.ts

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { EnvironmentConfig, RsbuildConfig, Rspack } from '@rsbuild/core';
2-
import type { PluginDtsOptions } from 'rsbuild-plugin-dts';
32
import type { GetAsyncFunctionFromUnion } from './utils';
43

54
export type Format = 'esm' | 'cjs' | 'umd' | 'mf';
@@ -44,21 +43,67 @@ export type Syntax =
4443
| string[];
4544

4645
export type Dts =
47-
| (Pick<
48-
PluginDtsOptions,
49-
'bundle' | 'distPath' | 'abortOnError' | 'build'
50-
> & {
46+
| {
47+
/**
48+
* Whether to bundle the DTS files.
49+
* @defaultValue `false`
50+
* @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsbundle}
51+
*/
52+
bundle?: boolean;
53+
/**
54+
* The output directory of DTS files.
55+
* @defaultValue {@link https://lib.rsbuild.dev/config/lib/dts#default-value}
56+
* @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsdistpath}
57+
*/
58+
distPath?: string;
59+
/**
60+
* Whether to generate DTS files with building the project references.
61+
* @defaultValue `false`
62+
* @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsbuild}
63+
*/
64+
build?: boolean;
65+
/**
66+
* Whether to abort the build process when an error occurs during DTS generation.
67+
* @defaultValue `true`
68+
* @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsabortonerror}
69+
*/
70+
abortOnError?: boolean;
71+
/**
72+
* Whether to automatically set the DTS file extension based on the {@link format} option.
73+
* @defaultValue `false`
74+
* @see {@link https://lib.rsbuild.dev/config/lib/dts#dtsautoextension}
75+
*/
5176
autoExtension?: boolean;
52-
})
77+
}
5378
| boolean;
5479

5580
export type AutoExternal =
5681
| boolean
5782
| {
83+
/**
84+
* Whether to automatically externalize dependencies of type `dependencies`.
85+
* @defaultValue `true`
86+
* @see {@link https://lib.rsbuild.dev/config/lib/auto-external#autoexternaldependencies}
87+
*/
5888
dependencies?: boolean;
89+
/**
90+
* Whether to automatically externalize dependencies of type `optionalDependencies`.
91+
* @defaultValue `true`
92+
* @see {@link https://lib.rsbuild.dev/config/lib/auto-external#autoexternaloptionaldependencies}
93+
*/
5994
optionalDependencies?: boolean;
60-
devDependencies?: boolean;
95+
/**
96+
* Whether to automatically externalize dependencies of type `peerDependencies`.
97+
* @defaultValue `true`
98+
* @see {@link https://lib.rsbuild.dev/config/lib/auto-external#autoexternalpeerdependencies}
99+
*/
61100
peerDependencies?: boolean;
101+
/**
102+
* Whether to automatically externalize dependencies of type `devDependencies`.
103+
* @defaultValue `false`
104+
* @see {@link https://lib.rsbuild.dev/config/lib/auto-external#autoexternaldevdependencies}
105+
*/
106+
devDependencies?: boolean;
62107
};
63108

64109
export type BannerAndFooter = {
@@ -68,12 +113,40 @@ export type BannerAndFooter = {
68113
};
69114

70115
export type Shims = {
116+
/**
117+
* Configure the shims for CommonJS output.
118+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimscjs}
119+
*/
71120
cjs?: {
121+
/**
122+
* Whether to inject shims for the `import.meta.url` in CommonJS output.
123+
* @defaultValue `true`
124+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimscjsimportmetaurl}
125+
*/
72126
'import.meta.url'?: boolean;
73127
};
128+
/**
129+
* Configure the shims for ESM output.
130+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimsesm}
131+
*/
74132
esm?: {
133+
/**
134+
* Whether to inject shims for the global `__filename` of CommonJS in ESM output.
135+
* @defaultValue `false`
136+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimsesm__filename}
137+
*/
75138
__filename?: boolean;
139+
/**
140+
* Whether to inject shims for the global `__dirname` of CommonJS in ESM output.
141+
* @defaultValue `false`
142+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimsesm__dirname}
143+
*/
76144
__dirname?: boolean;
145+
/**
146+
* Whether to inject shims for the global `require` of CommonJS in ESM output.
147+
* @defaultValue `false`
148+
* @see {@link https://lib.rsbuild.dev/config/lib/shims#shimsesmrequire}
149+
*/
77150
require?: boolean;
78151
};
79152
};
@@ -85,7 +158,7 @@ export type JsRedirect = {
85158
*/
86159
path?: boolean;
87160
/**
88-
* Whether to automatically add the file extension to import paths based on the JavaScript output files.
161+
* Whether to automatically redirect the file extension to import paths based on the JavaScript output files.
89162
* @defaultValue `true`
90163
*/
91164
extension?: boolean;
@@ -98,7 +171,7 @@ export type StyleRedirect = {
98171
*/
99172
path?: boolean;
100173
/**
101-
* Whether to automatically add the file extension to import paths based on the style output files.
174+
* Whether to automatically redirect the file extension to import paths based on the style output files.
102175
* @defaultValue `true`
103176
*/
104177
extension?: boolean;
@@ -113,7 +186,7 @@ type DtsRedirect = {
113186
export type Redirect = {
114187
/** Controls the redirect of the import paths of output JavaScript files. */
115188
js?: JsRedirect;
116-
/** Whether to redirect the import path of the style file. */
189+
/** Controls the redirect of the import paths of output style files. */
117190
style?: StyleRedirect;
118191
// TODO: support other redirects
119192
// asset?: boolean;

packages/plugin-dts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pluginDts({
7575
- **Type:** `boolean`
7676
- **Default:** `false`
7777

78-
Determines whether to generate DTS files while building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
78+
Whether to generate DTS files with building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
7979

8080
When this option is enabled, you must explicitly set `declarationDir` or `outDir` in `tsconfig.json` in order to meet the build requirements.
8181

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default {
130130
- **Type:** `boolean`
131131
- **Default:** `false`
132132

133-
Determines whether to generate DTS files while building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
133+
Whether to generate DTS files with building the project references. This is equivalent to using the `--build` flag with the `tsc` command. See [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) for more details.
134134

135135
::: note
136136

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ When set to `false`, the import path will not be effected by [resolve.alias](/co
9595

9696
### redirect.js.extension
9797

98-
Whether to automatically add the file extension to import paths based on the JavaScript output files.
98+
Whether to automatically redirect the file extension to import paths based on the JavaScript output files.
9999

100100
- **Type:** `boolean`
101101
- **Default:** `true`
@@ -106,9 +106,11 @@ When set to `false`, the file extension will remain unchanged from the original
106106

107107
## redirect.style
108108

109+
Controls the redirect of the import paths of output style files.
110+
109111
### redirect.style.path
110112

111-
Whether to automatically redirect the import path when importing style files, the rules are the same as [redirect.js.path](/config/lib/redirect#redirectjspath).
113+
Whether to automatically redirect the import paths of style output files, the rules are the same as [redirect.js.path](/config/lib/redirect#redirectjspath).
112114

113115
- **Type:** `boolean`
114116
- **Default:** `true`
@@ -137,7 +139,7 @@ import styles from '../foo.css'; // expected output of './dist/utils/index.js'
137139

138140
### redirect.style.extension
139141

140-
Whether to redirect style file extensions.
142+
Whether to automatically redirect the file extension to import paths based on the style output files.
141143

142144
- **Type:** `boolean`
143145
- **Default:** `true`

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Set the fields to `true` to enable the corresponding shims for CommonJS output.
4242

4343
### shims.cjs['import.meta.url']
4444

45+
Whether to inject shims for the `import.meta.url` in CommonJS output.
46+
4547
- **Default:** `true`
4648

4749
Options:
@@ -82,7 +84,7 @@ Set the fields to `true` to enable the corresponding shims for ESM output.
8284
8385
### shims.esm.\_\_filename
8486
85-
Whether to shim the global `__filename` of CommonJS in ESM output.
87+
Whether to inject shims for the global `__filename` of CommonJS in ESM output.
8688
8789
- **Default:** `false`
8890
@@ -112,7 +114,7 @@ Options:
112114
113115
### shims.esm.\_\_dirname
114116
115-
Whether to shim the global `__dirname` of CommonJS in ESM output.
117+
Whether to inject shims for the global `__dirname` of CommonJS in ESM output.
116118
117119
- **Default:** `false`
118120
@@ -141,7 +143,7 @@ Options:
141143
142144
### shims.esm.require
143145
144-
Whether to shim the global `require` of CommonJS in ESM output.
146+
Whether to inject shims for the global `require` of CommonJS in ESM output.
145147
146148
- **Default:** `false`
147149

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default {
130130
- **类型:** `boolean`
131131
- **默认值:** `false`
132132

133-
决定是否在构建项目引用时生成 DTS 文件。这相当于在 `tsc` 命令中使用 `--build` 标志。更多详细信息请参考 [项目引用](https://www.typescriptlang.org/docs/handbook/project-references.html)
133+
是否在生成 DTS 文件时构建项目的 references。这相当于在 `tsc` 命令中使用 `--build` 标志。更多详细信息请参考 [项目引用](https://www.typescriptlang.org/docs/handbook/project-references.html)
134134

135135
::: note
136136

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ overviewHeaders: [2, 3]
66

77
:::info
88

9-
`redirect` 是 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)的特定配置。在 bundle 模式下不会生效,因为所有输出文件都被打包成一个文件。所以,导入路径不存在因而不需要重定向。
9+
`redirect` 是 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)的特定配置。在 bundle 模式下不会生效,因为所有产物文件都被打包成一个文件。所以,导入路径不存在因而不需要重定向。
1010

1111
由于 bundleless 模式仍在开发中,未来将引入更多的重定向配置。
1212

@@ -46,13 +46,13 @@ const defaultRedirect = {
4646
};
4747
```
4848

49-
配置输出文件中导入路径的重定向。在 bundleless 模式下,通常需要使用别名或自动添加 ESM 产物的后缀。`redirect` 配置旨在解决这些问题。
49+
配置产物文件中导入路径的重定向。在 bundleless 模式下,通常需要使用别名或自动添加 ESM 产物的后缀。`redirect` 配置旨在解决这些问题。
5050

5151
常见的需要 redirect 的场景:
5252

5353
- 自动将 tsconfig.json 中 `compilerOptions.paths` 转换为正确的相对路径
5454

55-
例如,在 tsconfig.json 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }`输出文件将被重定向到正确的相对路径
55+
例如,在 tsconfig.json 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }`产物文件将被重定向到正确的相对路径
5656

5757
```ts
5858
import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓
@@ -64,7 +64,7 @@ const defaultRedirect = {
6464

6565
- 自动添加文件后缀
6666

67-
对于在 Node.js 中运行的 ESM 产物,必须指定模块导入的完整路径才能正确加载。Rslib 将根据输出文件自动添加后缀
67+
对于在 Node.js 中运行的 ESM 产物,必须指定模块导入的完整路径才能正确加载。Rslib 将根产物文件自动添加后缀
6868

6969
```ts
7070
import { foo } from './foo'; // './src/bar.ts' 的源码 ↓
@@ -76,39 +76,41 @@ const defaultRedirect = {
7676

7777
## redirect.js
7878

79-
控制输出 JavaScript 文件导入路径的重定向
79+
控制 JavaScript 产物文件导入路径的重定向
8080

8181
:::warning
8282
[output.externals](/config/rsbuild/output#outputexternals) 被配置且请求被匹配时,`redirect.js.path``redirect.js.extension` 都不会生效,最终重写的请求路径将完全由 [output.externals](/config/rsbuild/output#outputexternals) 控制。
8383
:::
8484

8585
### redirect.js.path
8686

87-
是否自动重定向 JavaScript 输出文件的导入路径
87+
是否自动重定向 JavaScript 产物文件的导入路径
8888

8989
- **类型:** `boolean`
9090
- **默认值:** `true`
9191

92-
当设置为 `true` 时,[resolve.alias](/config/rsbuild/resolve#resolvealias)[resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) 将生效并应用于输出文件的重写导入路径。对于 TypeScript 项目,您只需在 tsconfig.json 文件中配置 [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths)
92+
当设置为 `true` 时,[resolve.alias](/config/rsbuild/resolve#resolvealias)[resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) 将生效并应用于产物文件的重写导入路径。对于 TypeScript 项目,您只需在 tsconfig.json 文件中配置 [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths)
9393

9494
当设置为 `false` 时,导入路径将不受 [resolve.alias](/config/rsbuild/resolve#resolvealias)[resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) 和 tsconfig.json 的影响。
9595

9696
### redirect.js.extension
9797

98-
是否根据 JavaScript 输出文件自动添加文件扩展名到导入路径
98+
是否根据 JavaScript 产物文件自动重定向文件扩展名到导入路径
9999

100100
- **类型:** `boolean`
101101
- **默认值:** `true`
102102

103-
当设置为 `true` 时,无论原始扩展名或导入路径中是否指定,文件扩展名都将自动添加到输出文件的重写导入路径中
103+
当设置为 `true` 时,无论原始扩展名或导入路径中是否指定,文件扩展名都将自动添加到产物文件的重写导入路径中
104104

105105
当设置为 `false` 时,文件扩展名将保持原始导入路径中的不变(无论是否指定或指定为任意值)。
106106

107107
## redirect.style
108108

109+
控制样式产物文件导入路径的重定向。
110+
109111
### redirect.style.path
110112

111-
导入样式文件时是否自动重定向导入路径,规则与 [redirect.js.path](/config/lib/redirect#redirectjspath) 相同。
113+
是否自动重定向样式产物文件的导入路径,规则与 [redirect.js.path](/config/lib/redirect#redirectjspath) 相同。
112114

113115
- **类型:** `boolean`
114116
- **默认值:** `true`
@@ -137,12 +139,12 @@ import styles from '../foo.css'; // './dist/utils/index.js' 预期生成的代
137139

138140
### redirect.style.extension
139141

140-
是否重定向样式文件的扩展名
142+
是否根据样式产物文件自动重定向文件扩展名到导入路径
141143

142144
- **类型:** `boolean`
143145
- **默认值:** `true`
144146

145-
当设置为 `true` 时,导入普通样式文件时,路径将被重写为 `.css` 文件,导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时,路径将被重写为到对应的 JavaScript 输出文件
147+
当设置为 `true` 时,导入普通样式文件时,路径将被重写为 `.css` 文件,导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时,路径将被重写为到对应的 JavaScript 产物文件
146148

147149
当设置为 `false` 时,文件扩展名将保持原始导入路径中的不变。
148150

0 commit comments

Comments
 (0)