Skip to content

Commit 1f9ad44

Browse files
committed
docs: add
1 parent e079ba0 commit 1f9ad44

File tree

6 files changed

+281
-32
lines changed

6 files changed

+281
-32
lines changed

packages/core/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export type Dts =
101101
*/
102102
experiments?: {
103103
/**
104-
* [Experimental] Whether to generate declaration files with the `tsgo` compiler.
104+
* [Experimental] Whether to generate declaration files with `tsgo`.
105105
* @defaultValue `false`
106106
* @see {@link https://rslib.rs/config/lib/dts#dtsexperimentstsgo}
107107
*/

packages/plugin-dts/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pluginDts({
136136
});
137137
```
138138

139+
> When [experiments.tsgo](#experimentstsgo) is enabled, if the project also enables [build](#build) or emits declaration files with different extensions to the same directory, `dtsExtension` may not work correctly.
140+
139141
### alias
140142

141143
- **Type:** `Record<string, string>`
@@ -280,6 +282,40 @@ import { foo } from './foo.mjs'; // expected output of './dist/bar.d.mts'
280282

281283
- When set to `false`, the file extension will remain unchanged from the original import path in the rewritten import path of the output file (regardless of whether it is specified or specified as any value).
282284

285+
### experiments
286+
287+
- **Type:** `{ tsgo?: boolean }`
288+
- **Default:** `{}`
289+
290+
Whether to enable experimental features.
291+
292+
#### experiments.tsgo
293+
294+
- **Type:** `boolean`
295+
- **Default:** `false`
296+
297+
Whether to generate declaration files with [tsgo](https://github.com/microsoft/typescript-go).
298+
299+
To enable this option, you need to:
300+
301+
1. Install [@typescript/native-preview](https://www.npmjs.com/package/@typescript/native-preview) as a development dependency.
302+
303+
```bash
304+
npm add @typescript/native-preview -D
305+
```
306+
307+
2. Set `experiments.tsgo` to `true`.
308+
309+
```js
310+
pluginDts({
311+
experiments: {
312+
tsgo: true,
313+
},
314+
});
315+
```
316+
317+
> `tsgo` can provide faster generation of declaration files, especially for large projects. However, since `tsgo` is still experimental, there may be unresolved issues or limitations. Therefore, please make sure to thoroughly test it in your project before enabling this option.
318+
283319
## Contributing
284320

285321
Please read the [Contributing Guide](https://github.com/web-infra-dev/rslib/blob/main/CONTRIBUTING.md).

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type Dts =
1515
abortOnError?: boolean;
1616
autoExtension?: boolean;
1717
alias?: Record<string, string>;
18+
experiments?: {
19+
tsgo?: boolean;
20+
};
1821
}
1922
| boolean;
2023
```
@@ -216,7 +219,9 @@ When `dts.autoExtension` is set to `true`, the declaration file extension will b
216219

217220
::: note
218221

219-
It follows the same logic as [lib.autoExtension](/config/lib/auto-extension), but the default value is different since the declaration file extension may cause some issues with different module resolution strategies.
222+
1. It follows the same logic as [lib.autoExtension](/config/lib/auto-extension), but the default value is different since the declaration file extension may cause some issues with different module resolution strategies.
223+
224+
2. When [dts.experiments.tsgo](/config/lib/dts#dtsexperimentstsgo) is enabled, if the project also enables [dts.build](/config/lib/dts#dtsbuild) or emits declaration files with different extensions to the same directory, `dts.autoExtension` may not work correctly.
220225

221226
:::
222227

@@ -245,3 +250,42 @@ export default {
245250
],
246251
};
247252
```
253+
254+
### dts.experiments
255+
256+
- **Type:** `{ tsgo?: boolean }`
257+
- **Default:** `{}`
258+
259+
Whether to enable experimental features.
260+
261+
#### dts.experiments.tsgo
262+
263+
- **Type:** `boolean`
264+
- **Default:** `false`
265+
266+
Whether to generate declaration files with [tsgo](https://github.com/microsoft/typescript-go).
267+
268+
To enable this option, you need to install [@typescript/native-preview](https://www.npmjs.com/package/@typescript/native-preview) as a development dependency.
269+
270+
<PackageManagerTabs command="add @typescript/native-preview -D" />
271+
272+
```ts title="rslib.config.ts"
273+
export default {
274+
lib: [
275+
{
276+
dts: {
277+
// [!code highlight:3]
278+
experiments: {
279+
tsgo: true,
280+
},
281+
},
282+
},
283+
],
284+
};
285+
```
286+
287+
::: note
288+
289+
`tsgo` can provide faster generation of declaration files, especially for large projects. However, since `tsgo` is still experimental, there may be unresolved issues or limitations. Therefore, please make sure to thoroughly test it in your project before enabling this option.
290+
291+
:::

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

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,83 @@ Bundleless declaration files involves generating a separate declaration file for
4040

4141
## How to generate declaration files in Rslib
4242

43-
Rslib defaults to generating bundleless declaration files, which using [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) and bundle declaration files is also supported by [API Extractor](https://api-extractor.com/).
44-
45-
If you want to generate bundleless declaration files, you can:
46-
47-
- Set `dts: true` or `dts: { bundle: false }` in the Rslib configuration file.
43+
Rslib supports generating declaration files using both the [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) and [tsgo](https://github.com/microsoft/typescript-go), and also supports bundling declaration files with [API Extractor](https://api-extractor.com/).
44+
45+
| Type | Supported Method | Description |
46+
| ---------- | --------------------------------------- | -------------- |
47+
| bundleless | TypeScript Compiler API | Default method |
48+
| bundleless | tsgo | |
49+
| bundle | TypeScript Compiler API + API Extractor | Default method |
50+
| bundle | tsgo + API Extractor | |
51+
52+
### Generate bundleless declaration files
53+
54+
Configure in the Rslib config file:
55+
56+
```ts title="rslib.config.ts"
57+
export default {
58+
lib: [
59+
{
60+
dts: true; // [!code highlight]
61+
// or
62+
// [!code highlight:3]
63+
dts: {
64+
bundle: false;
65+
}
66+
},
67+
],
68+
};
69+
```
4870

49-
If you want to generate bundle declaration files, you can:
71+
### Generate bundle declaration files
5072

5173
1. Install `@microsoft/api-extractor` as `devDependencies`, which is the underlying tool used for bundling declaration files.
5274

5375
import { PackageManagerTabs } from '@theme';
5476

5577
<PackageManagerTabs command="add @microsoft/api-extractor -D" />
5678

57-
2. Set `dts: { bundle: true }` in the Rslib configuration file.
79+
2. Configure in the Rslib config file:
80+
81+
```ts title="rslib.config.ts"
82+
export default {
83+
lib: [
84+
{
85+
// [!code highlight:3]
86+
dts: {
87+
bundle: true;
88+
}
89+
},
90+
],
91+
};
92+
```
93+
94+
### Generate declaration files with tsgo
95+
96+
1. Install `@typescript/native-preview` as `devDependencies`:
97+
98+
<PackageManagerTabs command="add @typescript/native-preview -D" />
99+
100+
2. Configure in the Rslib config file:
101+
102+
```ts title="rslib.config.ts"
103+
export default {
104+
lib: [
105+
{
106+
dts: {
107+
// [!code highlight:3]
108+
experiments: {
109+
tsgo: true,
110+
},
111+
},
112+
},
113+
],
114+
};
115+
```
116+
117+
### Notes
58118

59-
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.
119+
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) or [tsgo](https://github.com/microsoft/typescript-go) generates only declaration files.
60120

61121
```json
62122
{
@@ -84,6 +144,7 @@ The priority from highest to lowest of final output directory of declaration fil
84144
| [dts.abortOnError](/config/lib/dts#dtsabortonerror) | Whether to abort the build process when an error occurs during declaration files generation. |
85145
| [dts.autoExtension](/config/lib/dts#dtsautoextension) | Whether to automatically set the declaration file extension based on the [format](/config/lib/format) option. |
86146
| [dts.alias](/config/lib/dts#dtsalias) | The path alias of the declaration files. |
147+
| [dts.experiments.tsgo](/config/lib/dts#dtsexperimentstsgo) | Whether to generate declaration files with [tsgo](https://github.com/microsoft/TypeScript/pull/48729). |
87148
| [banner.dts](/config/lib/banner#bannerdts) | Inject content into the top of each declaration output file. |
88149
| [footer.dts](/config/lib/footer#footerdts) | Inject content into the bottom of each declaration file. |
89150
| [redirect.dts.path](/config/lib/redirect#redirectdtspath) | Whether to automatically redirect the import paths of TypeScript declaration output files. |

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type Dts =
1515
abortOnError?: boolean;
1616
autoExtension?: boolean;
1717
alias?: Record<string, string>;
18+
experiments?: {
19+
tsgo?: boolean;
20+
};
1821
}
1922
| boolean;
2023
```
@@ -216,7 +219,9 @@ export default {
216219

217220
::: note
218221

219-
这遵循与 [lib.autoExtension](/config/lib/auto-extension) 相同的逻辑,但默认值不同,因为类型声明文件扩展名可能会在不同的模块解析策略中造成一些问题。
222+
1. 这遵循与 [lib.autoExtension](/config/lib/auto-extension) 相同的逻辑,但默认值不同,因为类型声明文件扩展名可能会在不同的模块解析策略中造成一些问题。
223+
224+
2. 当开启 [dts.experiments.tsgo](/config/lib/dts#dtsexperimentstsgo) 时,如果项目同时开启了 [dts.build](/config/lib/dts#dtsbuild) 或者将不同后缀的类型声明文件输出到同一目录,`dts.autoExtension` 无法正常生效。
220225

221226
:::
222227

@@ -245,3 +250,42 @@ export default {
245250
],
246251
};
247252
```
253+
254+
### dts.experiments
255+
256+
- **类型:** `{ tsgo?: boolean }`
257+
- **默认值:** `{}`
258+
259+
用于启用实验性功能。
260+
261+
#### dts.experiments.tsgo
262+
263+
- **类型:** `boolean`
264+
- **默认值:** `false`
265+
266+
是否使用 [tsgo](https://github.com/microsoft/typescript-go) 生成类型声明文件。
267+
268+
如果需要启用该选项,需要安装 [@typescript/native-preview](https://www.npmjs.com/package/@typescript/native-preview) 作为开发依赖。
269+
270+
<PackageManagerTabs command="add @typescript/native-preview -D" />
271+
272+
```ts title="rslib.config.ts"
273+
export default {
274+
lib: [
275+
{
276+
dts: {
277+
// [!code highlight:3]
278+
experiments: {
279+
tsgo: true,
280+
},
281+
},
282+
},
283+
],
284+
};
285+
```
286+
287+
::: note
288+
289+
`tsgo` 可以提供更快的类型声明文件生成速度,尤其是对于大型项目。然而,由于 `tsgo` 仍处于实验阶段,可能会存在一些未解决的问题或限制。因此,在启用该选项前,请确保在你的项目中进行充分测试。
290+
291+
:::

0 commit comments

Comments
 (0)