Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 158 additions & 5 deletions packages/plugin-dts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,171 @@
<img alt="Rslib Banner" src="https://assets.rspack.dev/rslib/rslib-banner.png">
</picture>

# Rslib
# rsbuild-plugin-dts

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.
An [Rsbuild plugin](https://www.npmjs.com/package/rsbuild-plugin-dts) to emit declaration files for TypeScript which is built-in in Rslib.

## Documentation
## Using in Rslib

https://lib.rsbuild.dev/
Read [DTS](https://lib.rsbuild.dev/guide/advanced/dts) and [lib.dts](https://lib.rsbuild.dev/config/lib/dts) for more details.

## Using in Rsbuild

Install:

```bash
npm add rsbuild-plugin-dts -D
```

Add plugin to `rsbuild.config.ts`:

```ts
// rsbuild.config.ts
import { pluginDts } from 'rsbuild-plugin-dts';

export default {
plugins: [pluginDts()],
};
```

## Options

### bundle

- **Type:** `boolean`
- **Default:** `false`

Whether to bundle the DTS files.

If you want to [bundle DTS](https://lib.rsbuild.dev/guide/advanced/dts#bundle-dts) files, you should:

1. Install `@microsoft/api-extractor` as a development dependency, which is the underlying tool used for bundling DTS files.

```bash
npm add @microsoft/api-extractor -D
```

2. Set `bundle` to `true`.

```js
pluginDts({
bundle: true,
});
```

### distPath

- **Type:** `string`

The output directory of DTS files. The default value follows the priority below:

1. The `distPath` value of the plugin options.
2. The `declarationDir` value in the `tsconfig.json` file.
3. The [output.distPath.root](https://rsbuild.dev/config/output/dist-path) value of Rsbuild configuration.

```js
pluginDts({
distPath: './dist-types',
});
```

### build

- **Type:** `boolean`
- **Default:** `false`

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.

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

### abortOnError

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

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

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.

```js
pluginDts({
abortOnError: false,
});
```

### dtsExtension

- **Type:** `string`
- **Default:** `'.d.ts'`

The extension of the DTS file.

```js
pluginDts({
dtsExtension: '.d.mts',
});
```

### autoExternal

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

Whether to automatically externalize dependencies of different dependency types and do not bundle them into the DTS file.

The default value of `autoExternal` is `true`, which means the following dependency types will not be bundled:

- `dependencies`
- `optionalDependencies`
- `peerDependencies`

And the following dependency types will be bundled:

- `devDependencies`

```js
pluginDts({
autoExternal: {
dependencies: true,
optionalDependencies: true,
peerDependencies: true,
devDependencies: false,
},
});
```

### banner

- **Type:** `string`
- **Default:** `undefined`

Inject content into the top of each DTS file.

```js
pluginDts({
banner: '/** @banner */',
});
```

### footer

- **Type:** `string`
- **Default:** `undefined`

Inject content into the bottom of each DTS file.

```js
pluginDts({
footer: '/** @footer */',
});
```

## Contributing

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

## License

Rslib is [MIT licensed](https://github.com/web-infra-dev/rslib/blob/main/LICENSE).
[MIT licensed](https://github.com/web-infra-dev/rslib/blob/main/LICENSE).
2 changes: 1 addition & 1 deletion packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PLUGIN_DTS_NAME = 'rsbuild:dts';
// use ts compiler API to generate bundleless dts
// use ts compiler API and api-extractor to generate dts bundle
// TODO: deal alias in dts
export const pluginDts = (options: PluginDtsOptions): RsbuildPlugin => ({
export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
name: PLUGIN_DTS_NAME,

setup(api) {
Expand Down
5 changes: 0 additions & 5 deletions website/docs/en/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,5 @@
"text": "Config",
"link": "/config/",
"activeMatch": "/config/"
},
{
"text": "API",
"link": "/api/javascript-api/core",
"activeMatch": "/api/"
}
]
4 changes: 4 additions & 0 deletions website/docs/en/config/lib/auto-external.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
overviewHeaders: [2, 3]
---

# lib.autoExternal

- **Type:**
Expand Down
4 changes: 4 additions & 0 deletions website/docs/en/config/lib/banner.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
overviewHeaders: [2, 3]
---

# lib.banner

- **Type:**
Expand Down
Loading
Loading