esbuild Adapter
@softarc/native-federation-esbuild v3 — the reference build adapter, framework-agnostic, esbuild with a rollup pre-pass for CommonJS packages.
@softarc/native-federation-esbuild is the reference implementation of the core's BuildAdapter contract. It is small on purpose: hand it to federationBuilder.init and the core can bundle exposed modules, shared mappings and shared packages without knowing anything about your framework.
npm i @softarc/native-federation @softarc/native-federation-esbuild
The package exports one ready-made adapter and one factory:
import { esBuildAdapter, createEsBuildAdapter } from '@softarc/native-federation-esbuild';
// zero-config — createEsBuildAdapter({ plugins: [] })
esBuildAdapter;
// configured
const adapter = createEsBuildAdapter({
plugins: [myEsbuildPlugin()],
fileReplacements: reactReplacements.prod,
});
How it bundles
Every entry point the core hands over is classified by whether it lives in node_modules:
- Workspace files — exposed modules and shared mappings — go straight through esbuild: bundled, ESM,
target: esnext, minified unlessdevis on, with the core's externals list applied. - Packages get a rollup pre-pass first. Rollup resolves the package with
@rollup/plugin-commonjsand@rollup/plugin-node-resolve, replacesprocess.env.NODE_ENVwithdevelopmentorproduction, and writes an ESM file intonode_modules/.tmp/<mangled package name>. That file is then the esbuild entry point.
The pre-pass exists because esbuild alone cannot always convert CommonJS packages that build their exports object dynamically — React being the canonical case. See React & CJS Interop.
Output is written by the adapter itself (esbuild runs with write: false), with [name]-[hash] naming when the core asks for hashing.
In this section
- Getting Started — a complete build script for a host and a remote.
- Adapter Configuration — every field on
EsBuildAdapterConfig. - React & CJS Interop —
fileReplacementsand the CommonJS story.
Related
- Core → Build Adapters — the contract this implements.
- Adapters — the other adapters.