Skip to content

Commit 08beddb

Browse files
committed
chore: update
1 parent 4baf91b commit 08beddb

File tree

5 files changed

+182
-1
lines changed

5 files changed

+182
-1
lines changed

website/docs/en/config/lib/auto-external.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
overviewHeaders: [2, 3]
3+
---
4+
15
# lib.autoExternal
26

37
- **Type:**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
overviewHeaders: [2, 3]
3+
---
4+
15
# lib.banner
26

37
- **Type:**

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

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
---
2+
overviewHeaders: [2, 3]
3+
---
4+
15
# lib.dts
26

37
- **Type:**
48

59
```ts
610
type Dts =
711
| {
8-
build?: boolean;
912
bundle?: boolean;
1013
distPath?: string;
14+
build?: boolean;
1115
abortOnError?: boolean;
1216
autoExtension?: boolean;
1317
}
@@ -17,3 +21,166 @@ type Dts =
1721
- **Default:** `undefined`
1822

1923
Configure the generation of the TypeScript declaration files.
24+
25+
## Boolean Type
26+
27+
DTS generation is an optional feature, you can set `dts: true` to enable [bundleless DTS](/guide/advanced/dts#bundleless-dts) generation.
28+
29+
```ts title="rslib.config.ts" {5}
30+
export default {
31+
lib: [
32+
{
33+
format: 'esm',
34+
dts: true,
35+
},
36+
],
37+
};
38+
```
39+
40+
If you want to disable DTS generation, you can set `dts: false` or do not specify the `dts` option.
41+
42+
```ts title="rslib.config.ts" {5}
43+
export default {
44+
lib: [
45+
{
46+
format: 'esm',
47+
dts: false,
48+
},
49+
],
50+
};
51+
```
52+
53+
## Object Type
54+
55+
If you want to customize the DTS generation, you can set the `dts` option to an object.
56+
57+
### dts.bundle
58+
59+
- **Type:** `boolean`
60+
- **Default:** `false`
61+
62+
Whether to bundle the DTS files.
63+
64+
#### Example
65+
66+
If you want to generate [bundle DTS](/guide/advanced/dts#bundle-dts) files, you should:
67+
68+
- Install `@microsoft/api-extractor` as a development dependency.
69+
70+
import { PackageManagerTabs } from '@theme';
71+
72+
<PackageManagerTabs command="add @microsoft/api-extractor -D" />
73+
74+
- Set `dts.bundle` to `true`.
75+
76+
```ts title="rslib.config.ts" {5-7}
77+
export default {
78+
lib: [
79+
{
80+
format: 'esm',
81+
dts: {
82+
bundle: true,
83+
},
84+
},
85+
],
86+
};
87+
```
88+
89+
::: note
90+
91+
[@microsoft/api-extractor](https://github.com/microsoft/rushstack/tree/main/apps/api-extractor) only supports bundle DTS for single entry. If you want to generate bundle DTS for multiple entries, you can add extra lib configuration in [lib](/config/lib) field to split multiple entries into multiple lib configurations.
92+
93+
:::
94+
95+
### dts.distPath
96+
97+
- **Type:** `string`
98+
99+
The output directory of DTS files.
100+
101+
#### Default Value
102+
103+
The default value follows the priority below:
104+
105+
1. The `dts.distPath` value in the current lib configuration.
106+
2. The `declarationDir` value in the `tsconfig.json` file.
107+
3. The [output.distPath.root](/config/rsbuild/output#outputdistpath) value in the current lib configuration.
108+
109+
#### Example
110+
111+
```ts title="rslib.config.ts" {5-7}
112+
export default {
113+
lib: [
114+
{
115+
format: 'esm',
116+
dts: {
117+
distPath: './dist-types',
118+
},
119+
},
120+
],
121+
};
122+
```
123+
124+
### dts.build
125+
126+
- **Type:** `boolean`
127+
- **Default:** `false`
128+
129+
Determines whether to generate DTS files while building the project's references. This is equivalent to using the `--build` flag with the `tsc` command.
130+
131+
::: note
132+
133+
When this option is enabled, you must explicitly set `declarationDir` or `outDir` in `tsconfig.json` in order to meet the build requirements.
134+
135+
:::
136+
137+
### dts.abortOnError
138+
139+
- **Type:** `boolean`
140+
- **Default:** `true`
141+
142+
Whether to abort the build process when an error occurs during DTS generation.
143+
144+
By default, type errors will cause the build to fail. When `abortOnError` is set to `false`, the build will still succeed even if there are type issues in the code:
145+
146+
```ts title="rslib.config.ts" {5-7}
147+
export default {
148+
lib: [
149+
{
150+
format: 'esm',
151+
dts: {
152+
abortOnError: false,
153+
},
154+
},
155+
],
156+
};
157+
```
158+
159+
::: warning
160+
161+
When this configuration is disabled, there is no guarantee that the type files will be generated correctly.
162+
163+
:::
164+
165+
### dts.autoExtension
166+
167+
- **Type:** `boolean`
168+
- **Default:** `false`
169+
170+
Whether to automatically set the DTS file extension based on the [format](/config/lib/format) option.
171+
172+
#### Default Extension
173+
174+
By default that when `dts.autoExtension` is `false`, the DTS file extension will be `.d.ts`.
175+
176+
When `dts.autoExtension` is set to `true`, the DTS file extension will be:
177+
178+
- `.d.ts` with `esm` format and `.d.cts` with `cjs` format when `type: module` in `package.json`.
179+
180+
- `.d.ts` with `cjs` format and `.d.mts` with `esm` format when `type: commonjs` or no `type` field in `package.json`.
181+
182+
::: note
183+
184+
It follows the same logic as [lib.autoExtension](/config/lib/auto-extension), but the default value is different since the DTS file extension may cause some issues with different module resolution strategies.
185+
186+
:::

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
overviewHeaders: [2, 3]
3+
---
4+
15
# lib.footer
26

37
- **Type:**

website/docs/en/guide/advanced/dts.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ import { PackageManagerTabs } from '@theme';
5959
- Set `dts: { bundle: true }` in the Rslib configuration file.
6060

6161
You can refer to [lib.dts](/config/lib/dts) for more details about DTS configuration.
62+
63+
- Specify which third-party package types need to be bundled, refer to the [Handle Third-Party Dependencies](/guide/advanced/third-party-deps) documentation for more details about externals related configurations.

0 commit comments

Comments
 (0)