Import production runtime helpers from:
import {
createFederationInstance,
createFederationManifestPreloadPlan,
createFederationRuntimeScope,
createServerFederationInstance,
loadRemoteFromManifest,
warmFederationRemotes,
} from 'vite-plugin-federation/runtime';The runtime wraps @module-federation/runtime and adds manifest-first loading, SSR target
selection, preload helpers, rollout controls, and debug snapshots.
Creates a browser/runtime host instance and installs shared diagnostics plugins.
createFederationInstance({
name: 'shell',
remotes: [],
shared: {},
});Creates a server-side runtime instance with inBrowser: false and the Node remote entry loader.
Use this in SSR hosts before loading node-target remotes.
createServerFederationInstance({
name: 'ssr-shell',
remotes: [],
shared: {},
});Fetches and validates mf-manifest.json.
Important options:
cache,cacheTtl,forcefallbackUrlsstaleWhileRevalidatecircuitBreakerfetch,fetchInitretries,retryDelay,timeouthooks
const manifest = await fetchFederationManifest(catalogManifestUrl, {
cacheTtl: 30_000,
fallbackUrls: [catalogBackupManifestUrl],
staleWhileRevalidate: true,
timeout: 4_000,
});Fetches a manifest, selects the correct entry for the target, optionally verifies entry integrity, and registers the remote with the Module Federation runtime.
await registerManifestRemote('catalog', catalogManifestUrl, {
target: 'web',
shareScope: 'default',
integrity: true,
});For target: 'node', ssrRemoteEntry is selected first and remoteEntry is used only when no SSR
entry is declared.
Registers multiple manifest remotes concurrently.
await registerManifestRemotes({
catalog: catalogManifestUrl,
checkout: {
manifestUrl: checkoutManifestUrl,
cacheTtl: 60_000,
},
});Registers the manifest remote if needed and then loads an exposed module.
const remoteModule = await loadRemoteFromManifest('catalog/Button', catalogManifestUrl, {
cacheTtl: 30_000,
retries: 2,
timeout: 4_000,
});
const CatalogButton = remoteModule.default ?? remoteModule;Delegates to @module-federation/runtime and records load success/failure in
getFederationDebugInfo().
Invalidates manifest registration and re-registers the remote. Browser targets append a timestamp query to remote entries on forced refresh.
await refreshRemote('catalog', {
invalidateManifest: true,
timeout: 4_000,
});The runtime re-exports and wraps shared APIs:
loadShareloadShareSyncregisterShared
The wrappers record shared resolution graph entries, selected providers, fallbacks, version compatibility, and singleton conflicts.
Returns resolved CSS and JS asset URLs for one expose.
Returns deduped SSR-ready <link> descriptors for exposes.
const links = collectFederationManifestPreloadLinks(manifestUrl, manifest, ['./Button']);Options:
includeCssincludeJsincludeAsyncCssincludeAsyncJscrossorigin
Builds a route-level preload plan from actual route-to-expose usage and optional manifest
preload hints.
const plan = createFederationManifestPreloadPlan(manifestUrl, manifest, {
'/checkout': ['./Cart', './PaymentForm'],
});Additional options:
asyncChunkPolicy:'css'by default, or'none','js','all'.includeManifestHints: setfalseto ignore manifest-levelpreloadhints.
Creates scoped wrappers for tenant or experiment isolation. The scope injects runtimeKey into
manifest fetching, registration, remote loading, refreshing, and warmups.
const tenant = createFederationRuntimeScope('tenant-a');
await tenant.registerManifestRemote('catalog', manifestUrl, {
shareScope: 'tenant-a',
});runtimeKey partitions manifest cache, pending requests, circuit breaker state, registered manifest
remote debug records, and remote load metrics. Use tenant.getFederationDebugInfo() for a filtered
debug snapshot.
Registers selected manifest remotes and optionally calls runtime preloadRemote for each one.
await warmFederationRemotes({
catalog: {
manifestUrl: catalogManifestUrl,
preload: { resourceCategory: 'sync' },
},
});Set preload: false to warm only the manifest cache and remote registration.
registerManifestRemote and loadRemoteFromManifest support:
integrity: true;
integrity: {
mode: 'prefer-integrity' | 'integrity' | 'content-hash' | 'both';
}The runtime verifies metaData.remoteEntry or metaData.ssrRemoteEntry hashes before
registration. Results are visible in getFederationDebugInfo().runtime.manifestIntegrityChecks.
Verifies annotated expose and preload assets declared in a manifest. String assets are skipped by
default; set requireIntegrity: true when every declared asset must include integrity or
contentHash metadata.
await verifyFederationManifestAssets(manifestUrl, manifest, {
integrity: { mode: 'both' },
requireIntegrity: true,
});Manifest runtime controls accept:
hooks: {
manifestFetch(event) {},
remoteRegister(event) {},
remoteLoad(event) {},
remoteRefresh(event) {},
telemetry(event) {},
}Events include kind, stage, timestamp, and contextual fields such as manifestUrl,
sourceUrl, remoteId, runtimeKey, entry, target, status, statusCode, durationMs,
and error.
Returns diagnostics, runtime instance snapshot, registered remotes, manifest cache, fetch timeline, integrity checks, circuit breaker state, remote load metrics, shared providers, and shared resolution graph.
Clears manifest cache, node module cache, registration requests, debug histories, and shared resolution history. Use only in tests or controlled runtime resets.
The runtime also re-exports selected Module Federation runtime helpers:
getInstancegetRemoteEntrygetRemoteInfoloadScriptloadScriptNodepreloadRemoteregisterGlobalPluginsregisterPluginsregisterRemotes