Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(QA): add how to external module in DTS #706

Merged
merged 3 commits into from
Jan 24, 2025
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
21 changes: 21 additions & 0 deletions website/docs/en/guide/faq/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,24 @@ export default {
},
};
```

## d.ts generation

### How to additionally exclude specified dependencies when `dts.bundle` is `true`?

Rslib uses [rsbuild-plugin-dts](https://github.com/web-infra-dev/rslib/blob/main/packages/plugin-dts/README.md) to generate d.ts files, which supports configuration via [output.externals](/config/rsbuild/output#outputtarget) for excluding certain dependencies from bundled d.ts files.

For example, a typical React component library often does not declare @types/react in peerDependencies but only in devDependencies. Following the [autoExternal](/config/lib/auto-external) logic for dependency handling, Rslib will attempt to bundle @types/react into the d.ts artifact during the build. However, in practice, a component library should not bundle @types/react.

In this scenario, you can configure [output.externals](/config/rsbuild/output#outputtarget) to exclude @types/react.

```ts title="rslib.config.ts"
export default {
lib: [
// ...
],
output: {
externals: ['@types/react'],
},
};
```
21 changes: 21 additions & 0 deletions website/docs/zh/guide/faq/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,24 @@ export default {
},
};
```

## d.ts 生成

### 如何在 `dts.bundle` 为 `true` 时额外排除指定的依赖?

Rslib 通过 [rsbuild-plugin-dts](https://github.com/web-infra-dev/rslib/blob/main/packages/plugin-dts/README.md) 完成对 d.ts 文件的生成,该插件支持通过 [output.externals](/config/rsbuild/output#outputtarget) 进行配置,用于从打包后的 d.ts 文件中排除指定的依赖。

举个例子:常见的 React 组件库通常不会将 @types/react 声明在 peerDependencies 中,而是仅声明在 devDependencies,按照 [autoExternal](/config/lib/auto-external) 处理依赖的逻辑,在打包时 Rslib 会尝试将 @types/react 一同打包进 d.ts 产物中,但在实践中组件库并不应该打包 @types/react。

此时可以通过配置 [output.externals](/config/rsbuild/output#outputtarget) 来排除 @types/react。

```ts title="rslib.config.ts"
export default {
lib: [
// ...
],
output: {
externals: ['@types/react'],
},
};
```
Loading