@module-federation/vite 1.19.0 → 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 +44 -0
- package/lib/index.d.ts +22 -1
- package/lib/index.js +885 -229
- package/lib/{pluginDts-Cd2opGcZ.js → pluginDts-Dbbi4cnh.js} +17 -11
- package/lib/{ssrEntryLoader-CuZVKlRm.js → ssrEntryLoader-BUD1-3Z2.js} +7 -4
- package/lib/{ssrVmStrategy-Dpw20xiw.js → ssrVmStrategy-C_cJtu5V.js} +1 -1
- package/lib/utils/injectExternalRuntimeCorePlugin.d.ts +21 -0
- package/lib/utils/injectExternalRuntimeCorePlugin.js +54 -0
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -70,6 +70,10 @@ With **@module-federation/vite**, the process becomes delightfully simple, you w
|
|
|
70
70
|
> This example is with [Vue.js](https://vuejs.org/)</br>
|
|
71
71
|
> The @module-federation/vite configuration remains the same for different frameworks.
|
|
72
72
|
|
|
73
|
+
## Migrating from OriginJS
|
|
74
|
+
|
|
75
|
+
Migrating from `@originjs/vite-plugin-federation` requires an explicit remote-entry format and runtime review, particularly for dynamic remotes, shared dependencies, and mixed bundlers. See the [OriginJS migration guide](./docs/MIGRATING_FROM_ORIGINJS.md) for step-by-step migration and incremental deployment guidance.
|
|
76
|
+
|
|
73
77
|
## Dedicated configuration file
|
|
74
78
|
|
|
75
79
|
You can keep Module Federation options in `module-federation.config.ts`.
|
|
@@ -291,6 +295,46 @@ After creating the secondary artifact, the deployment service must publish it to
|
|
|
291
295
|
|
|
292
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.
|
|
293
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
|
+
|
|
294
338
|
## ⚠️ `codeSplitting` settings are controlled by the plugin
|
|
295
339
|
|
|
296
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 };
|