@zonekit/federation-preset
v0.2.0
Published
Shared dependency locking, preset builder, and compatibility validation for Module Federation
Downloads
88
Maintainers
Readme
@zonekit/federation-preset
Shared-dependency presets for Zonekit federation setups.
Use @zonekit/federation-preset when you want one place to define shared dependency rules for all remotes and hosts. It helps you lock shared dependency policy, validate zone configs against that policy, and convert a Zonekit federation config into bundler-specific plugin config for webpack, Vite, or Rspack.
This package does not install or register the federation plugin for you. It produces validated config objects that you pass into your bundler plugin setup.
Installation
pnpm add @zonekit/federation-presetInstall only the bundler peer dependency you actually use.
Quick start
import { createFederationPreset, createWebpackAdapter } from "@zonekit/federation-preset";
const preset = createFederationPreset({
shared: {
react: { singleton: true, requiredVersion: "^18.2.0", eager: true },
"react-dom": { singleton: true, requiredVersion: "^18.2.0", eager: true },
},
});
const zoneFederation = {
name: "dashboard",
exposes: { "./Widget": "./src/widget.tsx" },
shared: {
react: { singleton: true, requiredVersion: "^18.2.0" },
"react-dom": { singleton: true, requiredVersion: "^18.2.0" },
},
};
const applied = preset.apply(zoneFederation);
const validation = preset.validate(zoneFederation);
const pluginConfig = preset.toPluginConfig(zoneFederation, createWebpackAdapter());
void applied;
void validation;
void pluginConfig;Recommended workflow
- Define one preset near the root of your workspace.
- Reuse it everywhere you generate bundler federation config.
- Validate each zone against the preset in CI so shared dependency drift is caught early.
- Use the bundler adapter that matches your host or remote build tool.
Key exports
Preset
createFederationPreset(options)creates a reusable preset with locked shared dependencies.preset.apply(zone)merges preset shared dependencies into a zone federation config.preset.extend(overrides)creates a derived preset with additional shared rules.preset.validate(zone)checks oneFederationConfigagainst preset rules.preset.toPluginConfig(zone, adapter)produces bundler-specific plugin config from aFederationConfig.
Bundler adapters
createWebpackAdapter()for webpackModuleFederationPluginconfig objects.createViteAdapter()for Vite federation plugin config objects.createRspackAdapter()for Rspack Module Federation plugin config objects.
Validation
validatePresetCompatibility(preset, zones)validates multipleZoneConfigentries in one call.createPresetValidator(preset)creates a reusable validator function for CI or custom checks.
Notes
- Validation errors are driven mostly by shared dependency semver compatibility and singleton rules.
- A dependency that appears in a zone but not in the preset is reported as a warning, not an error.
toPluginConfig()returns plain config objects; you still need to wire them into the bundler plugin your stack uses.
Peer dependencies
All peer dependencies are optional -- install only the bundler you use:
| Package | Version |
|---|---|
| webpack | ^5.0.0 (optional) |
| vite | ^5.0.0 \|\| ^6.0.0 (optional) |
| @rspack/core | >=0.5.0 (optional) |
License
MIT
Read more:
