@module-federation/vite 1.19.1 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -295,6 +295,46 @@ After creating the secondary artifact, the deployment service must publish it to
295
295
 
296
296
  This deployment step is separate from the local Vite build; the plugin only emits the metadata and runtime support needed by the service. If the Snapshot is not updated, the artifact cannot be fetched, the versions do not match, or the artifact does not provide all required exports, the runtime ignores the optimized artifact and safely loads the complete shared dependency instead.
297
297
 
298
+ ## External runtime (`experiments`)
299
+
300
+ Share one `@module-federation/runtime-core` instance from a pure consumer host so remotes do not bundle their own copy. Pair the flags — remotes with `externalRuntime` require a host that provides the global.
301
+
302
+ **Host (pure consumer, no `exposes`):**
303
+
304
+ ```ts
305
+ federation({
306
+ name: "host",
307
+ remotes: {
308
+ remote: {
309
+ type: "module",
310
+ name: "remote",
311
+ entry: "http://localhost:5176/remoteEntry.js",
312
+ },
313
+ },
314
+ experiments: {
315
+ provideExternalRuntime: true,
316
+ },
317
+ });
318
+ ```
319
+
320
+ **Remote:**
321
+
322
+ ```ts
323
+ federation({
324
+ name: "remote",
325
+ filename: "remoteEntry.js",
326
+ exposes: {
327
+ "./App": "./src/App.tsx",
328
+ },
329
+ experiments: {
330
+ externalRuntime: true,
331
+ },
332
+ });
333
+ ```
334
+
335
+ `provideExternalRuntime` injects a local runtime plugin that publishes `runtime-core` on `globalThis._FEDERATION_RUNTIME_CORE`. `externalRuntime` rewrites imports of `@module-federation/runtime-core` to read that global. Using `provideExternalRuntime` together with `exposes` throws — only pure consumers may provide the runtime.
336
+ The `externalRuntime` rewrite applies to the browser remote graph; SSR remote entries continue to resolve `@module-federation/runtime-core` from Node so they do not depend on the browser global.
337
+
298
338
  ## ⚠️ `codeSplitting` settings are controlled by the plugin
299
339
 
300
340
  Do not set either `build.rollupOptions.output.codeSplitting` or
package/lib/index.d.ts CHANGED
@@ -123,7 +123,28 @@ type ModuleFederationOptions = {
123
123
  * add any other Node-only packages that should not be bundled into the SSR entry.
124
124
  */
125
125
  ssrExternals?: string[];
126
+ /**
127
+ * Experimental Module Federation capabilities.
128
+ *
129
+ * @see https://module-federation.io/configure/experiments
130
+ */
131
+ experiments?: PluginExperimentsOptions;
126
132
  };
133
+ interface PluginExperimentsOptions {
134
+ /**
135
+ * Treat `@module-federation/runtime-core` as an external that reads
136
+ * `globalThis._FEDERATION_RUNTIME_CORE` at runtime. Pair with a host that
137
+ * sets `provideExternalRuntime: true`.
138
+ */
139
+ externalRuntime?: boolean;
140
+ /**
141
+ * Pure-consumer only (no `exposes`). Injects a local runtime plugin that
142
+ * publishes `runtime-core` on `globalThis._FEDERATION_RUNTIME_CORE`.
143
+ */
144
+ provideExternalRuntime?: boolean;
145
+ /** Generate the React SSR/hydration island capability for eligible exposes. */
146
+ ssrMode?: 'ISLAND';
147
+ }
127
148
  type HostInitInjectLocationOptions = 'entry' | 'html';
128
149
  interface PluginDevOptions {
129
150
  disableLiveReload?: boolean;
@@ -203,4 +224,4 @@ interface DtsHostOptions {
203
224
  declare function federation(mfUserOptions: ModuleFederationOptions): any[];
204
225
  declare function createModuleFederationConfig<T extends ModuleFederationOptions>(options: T): T;
205
226
  //#endregion
206
- export { type ModuleFederationOptions, type PluginManifestOptions, type TreeShakingConfig, createModuleFederationConfig, federation };
227
+ export { type ModuleFederationOptions, type PluginExperimentsOptions, type PluginManifestOptions, type TreeShakingConfig, createModuleFederationConfig, federation };