Use an External Runtime via experiments
mainTo avoid remotes bundling their own copy of @module-federation/runtime-core, you can share a single instance from a pure consumer host. This is achieved using the experiments configuration.
Implementation Pattern
- Host (Pure Consumer): Must set
experiments.provideExternalRuntime: true. This publishes the runtime toglobalThis._FEDERATION_RUNTIME_CORE. Note: A host can only provide the runtime if it does not useexposes. - Remote: Must set
experiments.externalRuntime: true. This rewrites imports of@module-federation/runtime-coreto use the global instance.
Note: externalRuntime applies to the browser remote graph. SSR remotes will continue to resolve the runtime from Node.
// Host (pure consumer, no 'exposes')
federation({
name: "host",
remotes: {
remote: {
type: "module",
name: "remote",
entry: "http://localhost:5176/remoteEntry.js",
},
},
experiments: {
provideExternalRuntime: true,
},
});
// Remote
federation({
name: "remote",
filename: "remoteEntry.js",
exposes: {
"./App": "./src/App.tsx",
},
experiments: {
externalRuntime: true,
},
});