@softarc/native-federation
v4.10.1
Published
[](https://www.npmjs.com/package/@softarc/native-federation) [](https://www.npmjs.com/package/@softarc/native-
Keywords
Readme
@softarc/native-federation
The build-tool and framework agnostic core of Native Federation: the mental model of Module Federation, implemented on browser standards (ES modules and import maps) for Micro Frontends and plugin-based architectures.
[!NOTE] This is v4. Upgrading? See the migration guide. The v3 source lives in the module-federation-plugin repository.
Features
- Any framework, any bundler — the core talks to your bundler through a small adapter contract.
- Web standards — remotes are plain ES modules wired together by an import map, no custom loader necessary (polyfill support via es-module-shims).
- Shared dependencies — load a library once across host and remotes, with semver-aware version negotiation.
- Fast — shared dependencies are bundled once and cached across builds.
Which package do I need?
This package is the low-level builder. Most apps use it through an adapter:
| You are… | Use |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Building an Angular app | @angular-architects/native-federation |
| Building with esbuild (React, vanilla) | @softarc/native-federation-esbuild |
| Loading remotes into a host page | @softarc/native-federation-orchestrator |
| Wiring a custom stack or new adapter | this package — build your own adapter |
Install
npm i @softarc/native-federation @softarc/native-federation-esbuild esbuildThe usage below builds with esbuild. Core does not install a bundler, so install the one your build script imports next to its adapter.
Usage
Describe what an application shares and exposes in federation.config.(m)js:
import { withNativeFederation, fromPackageJson } from '@softarc/native-federation/config';
export default withNativeFederation({
name: 'mfe1',
exposes: {
'./component': './mfe1/component',
},
shared: fromPackageJson({
singleton: true,
strictVersion: true,
requiredVersion: 'auto',
}),
});Then wrap your own build with the three federationBuilder calls:
import * as esbuild from 'esbuild';
import { federationBuilder } from '@softarc/native-federation';
import { esBuildAdapter } from '@softarc/native-federation-esbuild';
await federationBuilder.init({
options: {
workspaceRoot: process.cwd(),
outputPath: 'dist/mfe1',
tsConfig: 'tsconfig.json',
federationConfig: 'mfe1/federation.config.js',
},
adapter: esBuildAdapter,
});
// Run your bundler, keeping the shared dependencies external
await esbuild.build({ /* ... */ external: federationBuilder.externals });
// Bundle shared + exposed modules and write remoteEntry.json
await federationBuilder.build();The resulting remoteEntry.json is loaded at runtime by the orchestrator.
For the full walkthrough, see Getting Started or the end-to-end tutorial.
Documentation
- Mental model — hosts, remotes and shared dependencies
- Configuration — every option on
withNativeFederation - Sharing dependencies —
fromPackageJson,share,shareAll, secondary entry points - Build process — the builder lifecycle and watch mode
- Build artifacts — what ends up in
remoteEntry.json - API reference
- FAQ
Using an AI coding assistant? Point it at llms.txt.
Contributing
Issues and pull requests are welcome — see CONTRIBUTING.md.
Credits
Big thanks to Zack Jackson for originally coming up with Module Federation and its mental model, and to Florian Rappl and the Angular Architects team for their feedback and contributions. Find the current team behind native-federation on our documentation website.
