Skip to content

Commit 37b624a

Browse files
committed
chore: update
1 parent 08beddb commit 37b624a

File tree

3 files changed

+158
-7
lines changed

3 files changed

+158
-7
lines changed

packages/plugin-dts/README.md

Lines changed: 156 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,169 @@
22
<img alt="Rslib Banner" src="https://assets.rspack.dev/rslib/rslib-banner.png">
33
</picture>
44

5-
# Rslib
5+
# rsbuild-plugin-dts
66

7-
Rslib is a library development tool powered by [Rsbuild](https://rsbuild.dev). It allows library developers to leverage the knowledge and ecosystem of webpack and Rspack.
7+
An Rsbuild plugin to emit declaration files for TypeScript which is built-in in Rslib.
88

9-
## Documentation
9+
## Using in Rslib
1010

11-
https://lib.rsbuild.dev/
11+
Read [DTS](https://lib.rsbuild.dev/guide/advanced/dts#dts) and [lib.dts](https://lib.rsbuild.dev/config/lib/dts) for more details.
12+
13+
## Using in Rsbuild
14+
15+
Install:
16+
17+
```bash
18+
npm add rsbuild-plugin-dts -D
19+
```
20+
21+
Add plugin to your `rsbuild.config.ts`:
22+
23+
```ts
24+
// rsbuild.config.ts
25+
import { pluginDts } from 'rsbuild-plugin-dts';
26+
27+
export default {
28+
plugins: [pluginDts()],
29+
};
30+
```
31+
32+
## Options
33+
34+
### bundle
35+
36+
- **Type:** `boolean`
37+
- **Default:** `false`
38+
39+
Whether to bundle the DTS files.
40+
41+
If you want to generate [bundle DTS](https://lib.rsbuild.dev/guide/advanced/dts#bundle-dts) files, you should:
42+
43+
- Install `@microsoft/api-extractor` as a development dependency.
44+
45+
```bash
46+
npm add @microsoft/api-extractor -D
47+
```
48+
49+
- Set `bundle` to `true`.
50+
51+
```js
52+
pluginDts({
53+
bundle: true,
54+
});
55+
```
56+
57+
### distPath
58+
59+
- **Type:** `string`
60+
61+
The output directory of DTS files. The default value follows the priority below:
62+
63+
1. The `distPath` value of the plugin options.
64+
2. The `declarationDir` value in the `tsconfig.json` file.
65+
3. The [output.distPath.root](https://rsbuild.dev/config/output/dist-path) value of Rsbuild configuration.
66+
67+
```js
68+
pluginDts({
69+
distPath: './dist-types',
70+
});
71+
```
72+
73+
### build
74+
75+
- **Type:** `boolean`
76+
- **Default:** `false`
77+
78+
Determines whether to generate DTS files while building the project's references. This is equivalent to using the `--build` flag with the `tsc` command.
79+
80+
When this option is enabled, you must explicitly set `declarationDir` or `outDir` in `tsconfig.json` in order to meet the build requirements.
81+
82+
### abortOnError
83+
84+
- **Type:** `boolean`
85+
- **Default:** `true`
86+
87+
Whether to abort the build process when an error occurs during DTS generation.
88+
89+
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.
90+
91+
```js
92+
pluginDts({
93+
abortOnError: false,
94+
});
95+
```
96+
97+
### dtsExtension
98+
99+
- **Type:** `string`
100+
- **Default:** `'.d.ts'`
101+
102+
The extension of the DTS file.
103+
104+
```js
105+
pluginDts({
106+
dtsExtension: '.d.mts',
107+
});
108+
```
109+
110+
### autoExternal
111+
112+
- **Type:** `boolean`
113+
- **Default:** `true`
114+
115+
Whether to automatically externalize dependencies of different dependency types and do not bundle them into the DTS file.
116+
117+
The default value of `autoExternal` is `true`, which means the following dependency types will not be bundled:
118+
119+
- `dependencies`
120+
- `optionalDependencies`
121+
- `peerDependencies`
122+
123+
And the following dependency types will be bundled:
124+
125+
- `devDependencies`
126+
127+
```js
128+
pluginDts({
129+
autoExternal: {
130+
dependencies: true,
131+
optionalDependencies: true,
132+
peerDependencies: true,
133+
devDependencies: false,
134+
},
135+
});
136+
```
137+
138+
### banner
139+
140+
- **Type:** `string`
141+
- **Default:** `undefined`
142+
143+
Inject content into the top of each DTS file.
144+
145+
```js
146+
pluginDts({
147+
banner: '/** @banner */',
148+
});
149+
```
150+
151+
### footer
152+
153+
- **Type:** `string`
154+
- **Default:** `undefined`
155+
156+
```js
157+
pluginDts({
158+
footer: '/** @footer */',
159+
});
160+
```
161+
162+
Inject content into the bottom of each DTS file.
12163

13164
## Contributing
14165

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

17168
## License
18169

19-
Rslib is [MIT licensed](https://github.com/web-infra-dev/rslib/blob/main/LICENSE).
170+
[MIT licensed](https://github.com/web-infra-dev/rslib/blob/main/LICENSE).

packages/plugin-dts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const PLUGIN_DTS_NAME = 'rsbuild:dts';
5050
// use ts compiler API to generate bundleless dts
5151
// use ts compiler API and api-extractor to generate dts bundle
5252
// TODO: deal alias in dts
53-
export const pluginDts = (options: PluginDtsOptions): RsbuildPlugin => ({
53+
export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
5454
name: PLUGIN_DTS_NAME,
5555

5656
setup(api) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ When this option is enabled, you must explicitly set `declarationDir` or `outDir
141141

142142
Whether to abort the build process when an error occurs during DTS generation.
143143

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:
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.
145145

146146
```ts title="rslib.config.ts" {5-7}
147147
export default {

0 commit comments

Comments
 (0)