You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Rspack ModuleFederationPlugin to support enhanced configuration capabilities and environment targeting.
6
+
7
+
- Injects `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN` and `ENV_TARGET` as global constants using DefinePlugin, based on the new `experiments.optimization` options.
8
+
- Ensures parity with the Webpack plugin for build-time optimizations and environment-specific code paths.
9
+
- Enables tree-shaking and feature toggling in the runtime and SDK for both Rspack and Webpack builds.
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/configure/experiments.mdx
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,11 @@ new ModuleFederationPlugin({
10
10
experiments: {
11
11
asyncStartup: true,
12
12
externalRuntime: false,
13
-
provideExternalRuntime: false
13
+
provideExternalRuntime: false,
14
+
optimization: {
15
+
disableSnapshot: false,
16
+
target: 'web',
17
+
},
14
18
},
15
19
shared: {
16
20
react: {
@@ -59,3 +63,40 @@ Make sure to only configure it on the topmost consumer! If multiple consumers in
59
63
:::
60
64
61
65
Setting `true` will inject the MF runtime at the consumer.
66
+
67
+
## optimization
68
+
69
+
This object contains flags related to build-time optimizations that can affect the Module Federation runtime's size and behavior.
70
+
71
+
### disableSnapshot
72
+
73
+
- Type: `boolean`
74
+
- Required: No
75
+
- Default: `false`
76
+
77
+
When set to `true`, this option defines the `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN` global constant as `true` during the build. In the `@module-federation/runtime-core`, this prevents the `snapshotPlugin()` and `generatePreloadAssetsPlugin()` from being included and initialized within the FederationHost.
78
+
79
+
**Impact:**
80
+
***Benefit:** Can reduce the overall bundle size of the Module Federation runtime by excluding the code for these two plugins.
81
+
***Cost:** Disables the functionality provided by these plugins. The `snapshotPlugin` is crucial for the "mf-manifest protocol" – it's responsible for generating or providing runtime access to a build manifest (e.g., `mf-manifest.json`) containing metadata about exposed modules, shared dependencies, versions, and remotes. Disabling it means:
82
+
* The runtime loses access to this build manifest data.
83
+
* Features relying on the manifest, such as dynamic remote discovery, manifest-based version compatibility checks, advanced asset preloading (also handled by the removed `generatePreloadAssetsPlugin`), and potentially runtime debugging/introspection tools, will not function correctly or will be unavailable.
84
+
* Use this option only if you do not rely on these manifest-driven features and prioritize a minimal runtime footprint.
85
+
86
+
### target
87
+
88
+
- Type: `'web' | 'node'`
89
+
- Required: No
90
+
- Default: Inferred from Webpack's `target` option (usually `'web'`)
91
+
92
+
This option defines the `ENV_TARGET` global constant during the build, specifying the intended execution environment.
93
+
94
+
**Impact:**
95
+
***`target: 'web'`**: Optimizes the build for browser environments.
96
+
* Ensures browser-specific remote entry loading mechanisms are used (`loadEntryDom`).
97
+
* Crucially, enables tree-shaking/dead-code elimination for Node.js-specific code within the `@module-federation/sdk`. Functions like `createScriptNode` and `loadScriptNode`, along with their required Node.js built-in modules (e.g., `vm`, `path`, `http`), are completely removed from the bundle, significantly reducing its size.
98
+
***`target: 'node'`**: Optimizes the build for Node.js environments.
99
+
* Ensures Node.js-specific remote entry loading mechanisms are used (`loadEntryNode`).
100
+
* Includes the necessary Node.js-specific functions from the SDK (`createScriptNode`, `loadScriptNode`) in the bundle, allowing the federated application to function correctly in Node.js.
101
+
102
+
Explicitly setting this value is recommended to ensure the intended optimizations are applied, especially in universal or server-side rendering scenarios.
0 commit comments