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
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/configure/experiments.mdx
+38-16Lines changed: 38 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Experiments
2
2
3
-
The `experiments` configuration is used to enable experimental capabilities in the plugin.
3
+
The `experiments` configuration enables advanced and experimental capabilities in the plugin.
4
4
5
5
- Example
6
6
@@ -30,9 +30,9 @@ new ModuleFederationPlugin({
30
30
31
31
## asyncStartup
32
32
33
-
- Type: `boolean`
34
-
- Required: No
35
-
- Default: `false`
33
+
-**Type:**`boolean`
34
+
-**Required:** No
35
+
-**Default:**`false`
36
36
37
37
When `asyncStartup` is enabled, all Module Federation entrypoints will initialize asynchronously by default. This means:
38
38
@@ -46,17 +46,17 @@ When using this mode, all entrypoints will initialize asynchronously. If you're
46
46
47
47
## externalRuntime
48
48
49
-
- Type: `boolean`
50
-
- Required: No
51
-
- Default: `false`
49
+
-**Type:**`boolean`
50
+
-**Required:** No
51
+
-**Default:**`false`
52
52
53
53
After setting `true`, the external MF runtime will be used and the runtime provided by the consumer will be used. (Please make sure your consumer has `provideExternalRuntime: true` set, otherwise it will not run properly!)
54
54
55
55
## provideExternalRuntime
56
56
57
-
- Type: `boolean`
58
-
- Required: No
59
-
- Default: `false`
57
+
-**Type:**`boolean`
58
+
-**Required:** No
59
+
-**Default:**`false`
60
60
61
61
::: warning note
62
62
Make sure to only configure it on the topmost consumer! If multiple consumers inject runtime at the same time, the ones executed later will not overwrite the existing runtime.
@@ -70,9 +70,9 @@ This object contains flags related to build-time optimizations that can affect t
70
70
71
71
### disableSnapshot
72
72
73
-
- Type: `boolean`
74
-
- Required: No
75
-
- Default: `false`
73
+
-**Type:**`boolean`
74
+
-**Required:** No
75
+
-**Default:**`false`
76
76
77
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
78
@@ -83,11 +83,15 @@ When set to `true`, this option defines the `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLU
83
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
84
* Use this option only if you do not rely on these manifest-driven features and prioritize a minimal runtime footprint.
85
85
86
+
:::warning
87
+
**Caution:** Setting `disableSnapshot: true` will disable the mf-manifest protocol. This means you will lose TypeScript syncing support and hot module replacement (HMR) for federated modules. If you are only using `.js` remotes (not manifest-based remotes), you will not lose any functionality as the `js` remotes do not support these capabilities anyways.
88
+
:::
89
+
86
90
### target
87
91
88
-
- Type: `'web' | 'node'`
89
-
- Required: No
90
-
- Default: Inferred from Webpack's `target` option (usually `'web'`)
92
+
-**Type:**`'web' | 'node'`
93
+
-**Required:** No
94
+
-**Default:** Inferred from Webpack's `target` option (usually `'web'`)
91
95
92
96
This option defines the `ENV_TARGET` global constant during the build, specifying the intended execution environment.
93
97
@@ -100,3 +104,21 @@ This option defines the `ENV_TARGET` global constant during the build, specifyin
100
104
* 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
105
102
106
Explicitly setting this value is recommended to ensure the intended optimizations are applied, especially in universal or server-side rendering scenarios.
107
+
108
+
### Impact of Optimization Flags on `remoteEntry.js` Size
109
+
110
+
The following table demonstrates how different combinations of the `disableSnapshot`, `target: 'web'`, and `externalRuntime` optimization flags affect the size of the generated `remoteEntry.js` file. These measurements can help you choose the right trade-off between runtime features and bundle size for your use case.
| No optimization flags enabled | 69K | 21437 B | 19024 B |
115
+
|`disableSnapshot: true`| 65K | 20096 B | 17860 B |
116
+
|`target: 'web'`| 60K | 19314 B | 17105 B |
117
+
| Both enabled | 56K | 17998 B | 15982 B |
118
+
| Both enabled + `externalRuntime: true`| 14K | 5381 B | 4703 B |
119
+
| Both disabled + `externalRuntime: true`| 22K | 8222 B | 7269 B |
120
+
121
+
**Notes:**
122
+
- Enabling both `disableSnapshot` and `target: 'web'` provides the greatest reduction in bundle size, especially when combined with `externalRuntime: true`.
123
+
- Using the external runtime (`externalRuntime: true`) can dramatically reduce the size of your remote entry, but requires that the consumer provides the runtime.
124
+
- Smaller bundle sizes can lead to faster load times and improved performance, but may disable certain features (see above for details on what each flag does).
0 commit comments