Skip to content

Commit a9b6f04

Browse files
authored
docs: add some default strategy of declaration files generation (#841)
1 parent 475a3f2 commit a9b6f04

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ import { PackageManagerTabs } from '@theme';
5858

5959
2. Set `dts: { bundle: true }` in the Rslib configuration file.
6060

61+
It should be noted that during the generation of declaration files, Rslib will automatically enforce some configuration options in `tsconfig.json` to ensure that the [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) generates only declaration files.
62+
63+
```json
64+
{
65+
"compilerOptions": {
66+
"noEmit": false,
67+
"declaration": true,
68+
"emitDeclarationOnly": true
69+
}
70+
}
71+
```
72+
73+
The priority from highest to lowest of final output directory of declaration files:
74+
75+
- The configuration option [dts.distPath](/config/lib/dts#dtsdistpath)
76+
- The configuration option `declarationDir` in `tsconfig.json`
77+
- The configuration option [output.distPath.root](/config/rsbuild/output#outputdistpath)
78+
6179
::: tip
6280

6381
You can refer to [lib.dts](/config/lib/dts) for more details about declaration files configuration.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ import { PackageManagerTabs } from '@theme';
5858

5959
2. 在 Rslib 配置文件中设置 `dts: { bundle: true }`
6060

61+
需要注意的是,Rslib 在生成类型声明文件的过程中,默认会强制设置 `tsconfig.json` 中的一些配置项以保证 [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) 能够仅生成类型声明文件。
62+
63+
```json
64+
{
65+
"compilerOptions": {
66+
"noEmit": false,
67+
"declaration": true,
68+
"emitDeclarationOnly": true
69+
}
70+
}
71+
```
72+
73+
最终类型声明文件输出目录的优先级从高到低为:
74+
75+
- [dts.distPath](/config/lib/dts#dtsdistpath) 配置项
76+
- `tsconfig.json` 中的 `declarationDir` 配置项
77+
- [output.distPath.root](/config/rsbuild/output#outputdistpath) 配置项
78+
6179
::: tip
6280

6381
你可以参考 [lib.dts](/config/lib/dts) 获取更多有关类型声明文件配置的详细信息。

0 commit comments

Comments
 (0)