Skip to content

Commit 16e267d

Browse files
ScriptedAlchemymitchellrj
authored andcommitted
docs(website-new): refactor experiments page for clarity, consistency (module-federation#3783)
1 parent 9b1c47c commit 16e267d

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

apps/website-new/docs/en/configure/experiments.mdx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Experiments
22

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.
44

55
- Example
66

@@ -30,9 +30,9 @@ new ModuleFederationPlugin({
3030

3131
## asyncStartup
3232

33-
- Type: `boolean`
34-
- Required: No
35-
- Default: `false`
33+
- **Type:** `boolean`
34+
- **Required:** No
35+
- **Default:** `false`
3636

3737
When `asyncStartup` is enabled, all Module Federation entrypoints will initialize asynchronously by default. This means:
3838

@@ -46,17 +46,17 @@ When using this mode, all entrypoints will initialize asynchronously. If you're
4646

4747
## externalRuntime
4848

49-
- Type: `boolean`
50-
- Required: No
51-
- Default: `false`
49+
- **Type:** `boolean`
50+
- **Required:** No
51+
- **Default:** `false`
5252

5353
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!)
5454

5555
## provideExternalRuntime
5656

57-
- Type: `boolean`
58-
- Required: No
59-
- Default: `false`
57+
- **Type:** `boolean`
58+
- **Required:** No
59+
- **Default:** `false`
6060

6161
::: warning note
6262
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
7070

7171
### disableSnapshot
7272

73-
- Type: `boolean`
74-
- Required: No
75-
- Default: `false`
73+
- **Type:** `boolean`
74+
- **Required:** No
75+
- **Default:** `false`
7676

7777
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.
7878

@@ -83,11 +83,15 @@ When set to `true`, this option defines the `FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLU
8383
* 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.
8484
* Use this option only if you do not rely on these manifest-driven features and prioritize a minimal runtime footprint.
8585

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+
8690
### target
8791

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'`)
9195

9296
This option defines the `ENV_TARGET` global constant during the build, specifying the intended execution environment.
9397

@@ -100,3 +104,21 @@ This option defines the `ENV_TARGET` global constant during the build, specifyin
100104
* 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.
101105

102106
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.
111+
112+
| Optimization Flags | remoteEntry.js | Gzip Size | Brotli Size |
113+
|---------------------------------------------|:--------------:|:---------:|:-----------:|
114+
| 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

Comments
 (0)