Builder

Applies to

Reference for runEsBuildBuilder and EsBuildBuilderOptions — the Native Federation esbuild adapter's high-level entry point.

runEsBuildBuilder is the high-level entry point most projects use. It loads federation.config.js, registers the esbuild adapter with the core, runs the initial build, and — when watch is on — keeps a file watcher and rebuild queue running until you call close().

Signature

import { runEsBuildBuilder } from '@softarc/native-federation-esbuild';

const federation = await runEsBuildBuilder(
  federationConfigPath: string,
  options: EsBuildBuilderOptions,
): Promise<EsBuildBuilder>;

Minimal Call

const federation = await runEsBuildBuilder('federation.config.js', {
  outputPath: 'dist',
  entryPoints: ['src/bootstrap.tsx'],
});
await federation.close();

Everything else has a sensible default. The only required field is outputPath — the adapter throws [esbuild-builder] outputPath is required if it is missing.

EsBuildBuilderOptions

OptionTypeDefaultNotes
outputPathstringrequiredDirectory that receives remoteEntry.json and the bundled artifacts.
workspaceRootstringprocess.cwd()Resolved against cwd(). Useful when the build script runs from a monorepo root.
tsConfigstring'tsconfig.json'Forwarded to esbuild's tsconfig option for the source-code bundle.
cachePathstringcore defaultIf given, joined with workspaceRoot. Otherwise the core's getDefaultCachePath is used. See Caching.
projectNamestringForwarded to the core; used for logging and cache scoping in multi-project workspaces.
entryPointsstring[]Source entries for the federation build. Usually the files referenced by exposes in federation.config.js.
packageJsonstringPath to the project's package.json. Override when it is not next to the federation config.
devbooleanfalseEnables sourcemaps and disables minification in both the source-code and node-modules esbuild contexts. Also flips the process.env.NODE_ENV define to "development".
watchbooleanfalseStarts the file watcher and rebuild queue. The returned federation object stays live until you call close().
verbosebooleanfalseSets the adapter's log level to verbose. Rebuild cancellations, watcher events and full error stacks are logged.
rebuildDelaynumber50 (ms)Debounce before a rebuild fires after a file change. Clamped to a minimum of 10 ms internally.
cacheExternalArtifactsbooleantrueSet false to force the core to re-bundle shared node-modules on every build. Only useful when debugging cache issues.
adapterConfigEsBuildAdapterConfig{ plugins: [] }esbuild-specific extension points. See Adapter Configuration.

Return Value — EsBuildBuilder

interface EsBuildBuilder {
  federationInfo: FederationInfo;
  externals: string[];
  options: NormalizedEsBuildBuilderOptions;
  close(): Promise<void>;
}

Watch Mode

When watch: true, the adapter:

  1. Creates an NF file watcher that observes every source file the initial build touched.
  2. Queues a rebuild on change. Rebuilds are debounced by rebuildDelay and serialized through a RebuildQueue — a new change mid-build cancels the in-flight rebuild via AbortSignal rather than racing it.
  3. Calls rebuildForFederation on the core, which only re-bundles the entry points whose inputs changed.

Rebuild outcomes:

Lower-Level API — createEsBuildAdapter

If you drive buildForFederation / rebuildForFederation yourself (e.g. integrating with a custom dev server or another build tool's lifecycle), skip runEsBuildBuilder and construct just the adapter:

import { createEsBuildAdapter } from '@softarc/native-federation-esbuild';
import { setBuildAdapter, buildForFederation } from '@softarc/native-federation';

const adapter = createEsBuildAdapter({ plugins: [] });
setBuildAdapter(adapter);

await buildForFederation(config, normalizedOptions, externals);
await adapter.dispose();

createEsBuildAdapter returns an NFBuildAdapter with three methods:

For 99% of projects, runEsBuildBuilder is the right call. Reach for createEsBuildAdapter only when the core's built-in build loop doesn't fit your workflow.