From a89ece0c070567c1104807964d44368de7e6aab7 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Fri, 24 Jan 2025 16:31:27 +0800 Subject: [PATCH 1/3] docs(QA): add how to external module in DTS --- website/docs/en/guide/faq/features.mdx | 21 +++++++++++++++++++++ website/docs/zh/guide/faq/features.mdx | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/website/docs/en/guide/faq/features.mdx b/website/docs/en/guide/faq/features.mdx index fd456060f..574276dc2 100644 --- a/website/docs/en/guide/faq/features.mdx +++ b/website/docs/en/guide/faq/features.mdx @@ -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. + +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'], + }, +}; +``` diff --git a/website/docs/zh/guide/faq/features.mdx b/website/docs/zh/guide/faq/features.mdx index e71a4195f..7d8a0c3a8 100644 --- a/website/docs/zh/guide/faq/features.mdx +++ b/website/docs/zh/guide/faq/features.mdx @@ -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) 进行配置,用于排除指定的依赖。 + +举个例子:常见的 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'], + }, +}; +``` From c4b00e067abdc3e947d3ec93204b17a1bad4283d Mon Sep 17 00:00:00 2001 From: Wei Date: Fri, 24 Jan 2025 17:33:20 +0800 Subject: [PATCH 2/3] Update website/docs/zh/guide/faq/features.mdx Co-authored-by: Timeless0911 <50201324+Timeless0911@users.noreply.github.com> --- website/docs/zh/guide/faq/features.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/zh/guide/faq/features.mdx b/website/docs/zh/guide/faq/features.mdx index 7d8a0c3a8..cdce1d73d 100644 --- a/website/docs/zh/guide/faq/features.mdx +++ b/website/docs/zh/guide/faq/features.mdx @@ -97,7 +97,7 @@ export default { ### 如何在 `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) 进行配置,用于排除指定的依赖。 +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。 From df0c2a3bfe16ea6050d2f9c273b6e07654801d5b Mon Sep 17 00:00:00 2001 From: Wei Date: Fri, 24 Jan 2025 17:33:29 +0800 Subject: [PATCH 3/3] Update website/docs/en/guide/faq/features.mdx Co-authored-by: Timeless0911 <50201324+Timeless0911@users.noreply.github.com> --- website/docs/en/guide/faq/features.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/en/guide/faq/features.mdx b/website/docs/en/guide/faq/features.mdx index 574276dc2..ea99c7af9 100644 --- a/website/docs/en/guide/faq/features.mdx +++ b/website/docs/en/guide/faq/features.mdx @@ -97,7 +97,7 @@ export default { ### 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. +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.