Skip to content

Commit

Permalink
docs: improve dedupe guides
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Dec 1, 2024
1 parent d326de0 commit 6a0db62
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions website/docs/en/config/resolve/dedupe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default defineConfig({
});
```

Note that using `resolve.dedupe` to unify different major versions of a package, it may cause some packages to fail because they may depend on specific versions of APIs or features.

For example, if `foo` depends on a React 17-specific API or feature, then unifying React 17 and React 18 with React 18 using `resolve.dedupe` may cause `foo` to fail.

## How it works

`resolve.dedupe` is implemented based on [source.alias](/config/source/alias), it will get the path of the specified package through `require.resolve` in the project root directory and set it to the alias.
Expand Down
1 change: 1 addition & 0 deletions website/docs/en/guide/migration/vite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Here is the corresponding Rsbuild configuration for Vite configuration:
| publicDir | [server.publicDir](/config/server/public-dir) |
| assetsInclude | [source.assetsInclude](/config/source/assets-include) |
| resolve.alias | [source.alias](/config/source/alias) |
| resolve.dedupe | [resolve.dedupe](/config/resolve/dedupe) |
| resolve.conditions | [tools.rspack.resolve.conditionNames](/config/tools/rspack) |
| resolve.mainFields | [tools.rspack.resolve.mainFields](/config/tools/rspack) |
| resolve.extensions | [tools.rspack.resolve.extensions](/config/tools/rspack) |
Expand Down
2 changes: 2 additions & 0 deletions website/docs/en/guide/optimization/optimize-bundle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ For more details, see [Rsdoctor - Duplicate Dependency Problem](https://rsdoctor

We can eliminate duplicate dependencies with the package manager.

- Rsbuild provides the [resolve.dedupe](/config/resolve/dedupe) config, which allows you to force the specified packages to be resolved from the project root directory, thereby removing duplicate packages.

- If you are using `pnpm >= 7.26.0`, you can use the [pnpm dedupe](https://pnpm.io/cli/dedupe) command to upgrade and eliminate duplicate dependencies.

```bash
Expand Down
4 changes: 4 additions & 0 deletions website/docs/zh/config/resolve/dedupe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default defineConfig({
});
```

注意,如果使用 `resolve.dedupe` 将一个包的不同 major 版本统一为同一个,可能导致一些包无法正常工作,因为它们可能依赖于特定版本的 API 或功能。

例如,如果 `foo` 依赖了一个 React 17 特有的 API 或功能,此时将 React 17 和 React 18 统一为 React 18,就可能会导致 `foo` 无法正常工作。

## 实现原理

`resolve.dedupe` 是基于 [source.alias](/config/source/alias) 实现的,它会在当前项目的根目录下通过 `require.resolve` 获取指定包的路径,并设置到 alias 中。
Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/guide/migration/vite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Rsbuild 会在构建时自动注入 `<script>` 标签到生成的 HTML 文件中
| publicDir | [server.publicDir](/config/server/public-dir) |
| assetsInclude | [source.assetsInclude](/config/source/assets-include) |
| resolve.alias | [source.alias](/config/source/alias) |
| resolve.dedupe | [resolve.dedupe](/config/resolve/dedupe) |
| resolve.conditions | [tools.rspack.resolve.conditionNames](/config/tools/rspack) |
| resolve.mainFields | [tools.rspack.resolve.mainFields](/config/tools/rspack) |
| resolve.extensions | [tools.rspack.resolve.extensions](/config/tools/rspack) |
Expand Down
4 changes: 3 additions & 1 deletion website/docs/zh/guide/optimization/optimize-bundle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

### 消除重复依赖

我们可以通过社区中的一些工具来检测或消除重复依赖。
我们可以通过一些配置项和工具来检测或消除重复依赖。

- Rsbuild 提供了 [resolve.dedupe](/config/resolve/dedupe) 配置项,它允许你强制从项目根目录解析指定的包,从而移除重复包。

- 如果你在使用 `pnpm >= 7.26.0`,可以使用 pnpm 自带的 [pnpm dedupe](https://pnpm.io/cli/dedupe) 命令来升级和消除其中的重复依赖。

Expand Down

0 comments on commit 6a0db62

Please sign in to comment.