@module-federation/vite 1.19.1 → 1.20.1

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
@@ -1,6 +1,5 @@
1
1
  import { moduleFederationPlugin } from "@module-federation/sdk";
2
2
  import { ShareStrategy } from "@module-federation/runtime/types";
3
-
4
3
  //#region src/utils/normalizeModuleFederationOptions.d.ts
5
4
  interface RemoteObjectConfig {
6
5
  type?: string;
@@ -47,8 +46,10 @@ type ModuleFederationOptions = {
47
46
  * When false (default), the plugin will not process any CSS assets.
48
47
  * When true, all CSS assets are bundled into every exposed module.
49
48
  */
50
- bundleAllCSS?: boolean; /** Directory reserved for deploy-service generated secondary shared artifacts. */
51
- treeShakingDir?: string; /** Whether inferred usedExports metadata is injected into generated runtime records. */
49
+ bundleAllCSS?: boolean;
50
+ /** Directory reserved for deploy-service generated secondary shared artifacts. */
51
+ treeShakingDir?: string;
52
+ /** Whether inferred usedExports metadata is injected into generated runtime records. */
52
53
  injectTreeShakingUsedExports?: boolean;
53
54
  treeShakingSharedPlugins?: string[];
54
55
  treeShakingSharedExcludePlugins?: string[];
@@ -123,7 +124,28 @@ type ModuleFederationOptions = {
123
124
  * add any other Node-only packages that should not be bundled into the SSR entry.
124
125
  */
125
126
  ssrExternals?: string[];
127
+ /**
128
+ * Experimental Module Federation capabilities.
129
+ *
130
+ * @see https://module-federation.io/configure/experiments
131
+ */
132
+ experiments?: PluginExperimentsOptions;
126
133
  };
134
+ interface PluginExperimentsOptions {
135
+ /**
136
+ * Treat `@module-federation/runtime-core` as an external that reads
137
+ * `globalThis._FEDERATION_RUNTIME_CORE` at runtime. Pair with a host that
138
+ * sets `provideExternalRuntime: true`.
139
+ */
140
+ externalRuntime?: boolean;
141
+ /**
142
+ * Pure-consumer only (no `exposes`). Injects a local runtime plugin that
143
+ * publishes `runtime-core` on `globalThis._FEDERATION_RUNTIME_CORE`.
144
+ */
145
+ provideExternalRuntime?: boolean;
146
+ /** Generate the React SSR/hydration island capability for eligible exposes. */
147
+ ssrMode?: 'ISLAND';
148
+ }
127
149
  type HostInitInjectLocationOptions = 'entry' | 'html';
128
150
  interface PluginDevOptions {
129
151
  disableLiveReload?: boolean;
@@ -203,4 +225,4 @@ interface DtsHostOptions {
203
225
  declare function federation(mfUserOptions: ModuleFederationOptions): any[];
204
226
  declare function createModuleFederationConfig<T extends ModuleFederationOptions>(options: T): T;
205
227
  //#endregion
206
- export { type ModuleFederationOptions, type PluginManifestOptions, type TreeShakingConfig, createModuleFederationConfig, federation };
228
+ export { type ModuleFederationOptions, type PluginExperimentsOptions, type PluginManifestOptions, type TreeShakingConfig, createModuleFederationConfig, federation };