Skip to content

Plugin API Reference ​

Import the plugin from the package root:

ts
import federation from 'vite-plugin-federation';

Minimal Remote ​

ts
federation({
  name: 'catalog',
  exposes: {
    './Button': './src/Button.tsx',
  },
  manifest: true,
  shared: {
    react: {
      singleton: true,
      requiredVersion: '^19.2.4',
    },
    'react/': {
      singleton: true,
      requiredVersion: '^19.2.4',
    },
  },
});

Minimal Host ​

ts
federation({
  name: 'shell',
  remotes: {
    catalog: 'https://cdn.example.com/catalog/mf-manifest.json',
  },
  shared: {
    react: {
      singleton: true,
      requiredVersion: '^19.2.4',
    },
  },
});

ModuleFederationOptions ​

OptionTypeDefaultDescription
namestringrequiredPublic application/container name.
filenamestringremoteEntry-[hash]Browser remote entry filename.
varFilenamestringundefinedEmits an additional var-style remote entry for legacy hosts.
exposesRecord<string, string | ExposeConfig>{}Remote expose map. Keys should usually start with ./.
remotesRecord<string, string | RemoteObjectConfig>{}Host remote map. Values may be manifest URLs or object configs.
sharedstring[] | Record<string, string | SharedConfig>{}Shared dependency providers/consumers.
manifestboolean | PluginManifestOptionstrueEmits mf-manifest.json, mf-stats.json, and mf-debug.json when enabled.
dtsboolean | PluginDtsOptionsauto for TS projectsEnables type generation and/or type consumption through @module-federation/dts-plugin.
devboolean | PluginDevOptionsenabledControls devtools, live reload, remote HMR, type hints, and hot type reload.
compatboolean | CompatibilityOptionstrueEnables OriginJS-compatible virtual federation APIs.
shareStrategy'loaded-first' | 'version-first'version-firstShared provider selection strategy passed to the runtime.
shareScopestringdefaultDefault share scope.
publicPathstringVite base or autoPublic path used for generated manifest asset URLs.
bundleAllCSSbooleanfalseAdds all CSS assets from the bundle to every expose manifest entry.
runtimePluginsArray<string | [string, object]>[]Runtime plugin imports passed to Module Federation runtime init.
target'web' | 'node'build targetOverrides generated remote target. SSR builds normally use node.
virtualModuleDirstring__mf__virtualInternal virtual module directory name. It cannot contain /.
hostInitInjectLocation'entry' | 'html'htmlWhere host runtime initialization is injected.
moduleParseTimeoutnumber10Total module parsing timeout in seconds.
moduleParseIdleTimeoutnumberundefinedIdle parsing timeout in seconds, reset after every parsed module.

Exposes ​

ts
exposes: {
  './Button': './src/Button.tsx',
  './ManualCssButton': {
    import: './src/ManualCssButton.tsx',
    css: {
      inject: 'manual',
    },
  },
}

Expose config:

FieldTypeDescription
importstringSource module path.
css.injecttrue | false | 'head' | 'manual' | 'none'CSS injection mode.
dontAppendStylesToHeadbooleanOriginJS-compatible alias for manual CSS handling.

manual CSS exposes write hrefs to the global CSS bucket instead of appending styles to head. Use this for Shadow DOM or migration compatibility.

Do not expose the same file that index.html loads as a Vite module entry, such as src/main.ts, src/main.tsx, or src/main.js. That file should only bootstrap and mount the remote app. Expose components, routes, or loader modules instead. In dev, the plugin warns when an exposes entry points at the HTML module entry.

Remotes ​

String remotes are treated as manifest-first remotes:

ts
remotes: {
  catalog: 'https://cdn.example.com/catalog/mf-manifest.json',
}

Object remotes support compatibility fields:

ts
remotes: {
  legacy: {
    name: 'legacyRemote',
    entry: 'https://cdn.example.com/legacy/remoteEntry.js',
    type: 'module',
    entryGlobalName: 'legacyRemote',
    from: 'vite',
    format: 'esm',
    shareScope: 'default',
  },
}

Prefer manifest URLs for new applications. Use object remotes for legacy remoteEntry.js, OriginJS migration, or explicit systemjs/var compatibility.

Shared ​

ts
shared: {
  react: {
    singleton: true,
    strictSingleton: true,
    requiredVersion: '^19.2.4',
    strictVersion: true,
    allowNodeModulesSuffixMatch: true,
  },
  'react/': {
    singleton: true,
    requiredVersion: '^19.2.4',
    allowNodeModulesSuffixMatch: true,
  },
}

Shared config fields:

FieldTypeDescription
namestringRuntime share name override.
versionstringProvided version override.
shareScopestringShare scope override.
singletonbooleanPrefer one provider for this package.
strictSingletonbooleanTurn singleton conflicts into MFV-003 errors.
requiredVersionstringConsumer version range.
strictVersionbooleanTreat incompatible versions as strict failures.
allowNodeModulesSuffixMatchbooleanMatch pnpm/nested node_modules resolved ids by package suffix.
importstring | falseLocal fallback import override, or false for host-only shared modules.

Use trailing slash shared keys for package subpaths, for example react/ or @scope/pkg/.

Manifest Options ​

ts
manifest: {
  fileName: 'mf-manifest.json',
  filePath: 'federation',
  disableAssetsAnalyze: false,
}

Manifest builds also emit mf-stats.json and mf-debug.json. See manifest-protocol.md.

Dev Options ​

ts
dev: {
  remoteHmr: true, // opt in to host <-> remote HMR wiring
  devtools: true, // default; set false to disable the devtools endpoint/overlay
  disableLiveReload: true,
  disableHotTypesReload: false,
  disableDynamicRemoteTypeHints: false,
}

Devtools and DTS type hints are enabled by default in dev. Remote HMR is opt-in and only runs when dev.remoteHmr: true.

The devtools contract is documented in devtools-runtime-contract.md.

DTS Options ​

ts
dts: {
  generateTypes: {
    abortOnError: true,
  },
  consumeTypes: {
    typesOnBuild: true,
    abortOnError: true,
  },
}

In TypeScript projects, DTS support is enabled automatically unless dts: false is configured. See dts-workflows.md for complete DTS workflows and defaults.

Compatibility Options ​

ts
compat: {
  originjs: true,
  virtualFederationShim: true,
}

Disable compatibility for strictly manifest-first applications:

ts
compat: false;

See originjs-migration.md and compatibility-matrix.md.

Released under the MIT License.