Skip to content

Commit 09e0e3f

Browse files
committed
docs: optimize doc
1 parent dd999cb commit 09e0e3f

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

website/docs/en/plugins/webpack/tree-shake-shared-plugin.mdx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,41 @@ import { Stability, ApiMeta } from '@components/ApiMeta';
55
<ApiMeta stability={Stability.Experimental} />
66

77
**Overview**
8-
- Performs on-demand builds and export optimization for `shared` dependencies in Module Federation.
9-
- When `reshake` is false, enables `SharedUsedExportsOptimizerPlugin` to inject runtime used-exports.
10-
- If any shared entry has `treeshake: true` and `import !== false`, uses `IndependentSharedPlugin` to build independent artifacts per shared package and write back to stats/manifest.
8+
9+
- Performs on-demand build and export optimization for `shared` dependencies based on Module Federation configuration.
1110

1211
**Options**
13-
- `mfConfig`: `ModuleFederationPluginOptions` with `name`, `shared`, `library`, `manifest`, `injectUsedExports`.
14-
- `plugins`: extra plugins reused in independent builds.
15-
- `reshake`: whether to perform additional tree-shaking during independent builds.
12+
13+
- `mfConfig`: `ModuleFederationPluginOptions`, configuration passed to the Module Federation plugin.
14+
- `plugins`: extra plugins reused during independent builds.
15+
- `reshake`: whether to perform a second tree-shake during independent builds (typically used when the deployment platform has determined complete dependency info and triggers a fresh build to improve tree-shake accuracy for shared dependencies).
1616

1717
**Usage**
18+
1819
```js
1920
// rspack.config.js
2021
const { TreeShakeSharedPlugin } = require('@rspack/core');
2122

2223
module.exports = {
2324
plugins: [
2425
new TreeShakeSharedPlugin({
26+
reshake: true,
2527
mfConfig: {
2628
name: 'app',
2729
shared: {
2830
'lodash-es': { treeshake: true },
29-
react: { treeshake: true, requiredVersion: '18.3.1' }
3031
},
3132
library: { type: 'var', name: 'App' },
32-
manifest: { statsFileName: 'stats.json', manifestFileName: 'manifest.json' },
33-
injectUsedExports: true
33+
manifest: true,
3434
},
3535
plugins: [],
36-
reshake: false
37-
})
38-
]
36+
}),
37+
],
3938
};
4039
```
4140

4241
**Behavior**
43-
- Normalizes `shared` into `[shareName, SharedConfig][]`.
44-
- Registers `SharedUsedExportsOptimizerPlugin` when `reshake` is `false` to inject used exports from stats.
45-
- Triggers independent compilation for `treeshake` entries and writes produced assets back into stats/manifest.
4642

43+
- Normalizes `shared` into `[shareName, SharedConfig][]`.
44+
- Registers `SharedUsedExportsOptimizerPlugin` when `reshake` is `false` to inject used-exports from the stats manifest.
45+
- Triggers independent compilation for shared entries with `treeshake: true`, and writes the produced assets back to the `stats/manifest` (fallback fields).

website/docs/zh/plugins/webpack/tree-shake-shared-plugin.mdx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,41 @@ import { Stability, ApiMeta } from '@components/ApiMeta';
55
<ApiMeta stability={Stability.Experimental} />
66

77
**概览**
8-
- 基于模块联邦配置对 shared 依赖进行按需构建与导出优化。
9-
-`reshake` 模式下,启用 `SharedUsedExportsOptimizerPlugin` 注入运行时已用导出信息。
10-
- 当 shared 项存在 `treeshake: true``import !== false` 时,使用 `IndependentSharedPlugin` 为每个共享包生成独立产物并回填到清单。
8+
9+
基于模块联邦配置对 shared 依赖进行按需构建与导出优化。
1110

1211
**选项**
13-
- `mfConfig``ModuleFederationPluginOptions`,传入模块联邦的 name、shared、library、manifest、injectUsedExports。
12+
13+
- `mfConfig``ModuleFederationPluginOptions`,传入模块联邦插件所需要的配置项。
1414
- `plugins`:额外插件列表,可在独立编译中复用。
15-
- `reshake`:是否在独立编译阶段执行二次摇树优化。
15+
- `reshake`:是否在独立编译阶段执行二次摇树优化(二次摇树通常在部署平台确定了完整的依赖信息后重新触发的一次全新构建,提高共享依赖 treeshake 命中的准确率)
1616

1717
**使用示例**
18+
1819
```js
1920
// rspack.config.js
2021
const { TreeShakeSharedPlugin } = require('@rspack/core');
2122

2223
module.exports = {
2324
plugins: [
2425
new TreeShakeSharedPlugin({
26+
reshake: true,
2527
mfConfig: {
2628
name: 'app',
2729
shared: {
2830
'lodash-es': { treeshake: true },
29-
react: { treeshake: true, requiredVersion: '18.3.1' }
3031
},
3132
library: { type: 'var', name: 'App' },
32-
manifest: { statsFileName: 'stats.json', manifestFileName: 'manifest.json' },
33-
injectUsedExports: true
33+
manifest: true,
3434
},
3535
plugins: [],
36-
reshake: false
37-
})
38-
]
36+
}),
37+
],
3938
};
4039
```
4140

4241
**行为说明**
42+
4343
- 读取 `shared` 配置后标准化为 `[shareName, SharedConfig][]`
4444
-`reshake``false` 时,注册 `SharedUsedExportsOptimizerPlugin`,基于 stats 清单注入已用导出集合。
4545
-`treeshake` 的共享包触发独立编译,产出回写到 stats/manifest 中的 fallback 字段。
46-

0 commit comments

Comments
 (0)