Schematics
The adapter ships a small collection of schematics for the Angular CLI (and an Nx generator). They scaffold projects, migrate older setups forward, and tear federation back out cleanly when you no longer need it.
init / ng-add
ng add @angular-architects/native-federation-v4 \
--project <name> --port <port> --type <remote|host|dynamic-host>
Initializes a project for Native Federation. ng add and
ng g …:init both run the same factory.
Inputs
| Option | Type | Description |
|---|---|---|
--project |
string |
Project name from angular.json. Falls back to the
workspace's defaultProject, then to the first
project.
|
--port |
number |
Dev server port. Defaults to 4200. Also used as
the SSR port for hosts.
|
--type |
'host' | 'dynamic-host' | 'remote' |
Defaults to remote. Determines the shape of the
generated main.ts.
|
What it changes
-
Polyfills. Adds
es-module-shimsto the polyfills array (or to apolyfills.tsfile). -
Federation config. Generates
projects/<name>/federation.config.mjsfrom a template — for remotes, the project'sapp.component.tsis auto-detected and exposed as./Component. The template enablesdenseChunkingand adds an@angular/coreoverride withincludeSecondaries: { keepAll: true }. Skipped if a config already exists. -
tsconfig. Generates
projects/<name>/tsconfig.federation.json— extends the project'stsconfig.json, narrowstypesto[], and only includessrc/**/*.tsminus specs. -
angular.json. Switches the existing build to
@angular/build:application(if it isn't already), renames it toesbuild, renames the existing serve toserve-original, and slots the@angular-architects/native-federation-v4:buildbuilder intobuild+serve. See the angular.json layout. -
main.ts split. Moves your existing
main.tstobootstrap.tsand rewritesmain.tsto callinitFederation(...)first, then dynamicallyimport('./bootstrap'). The first argument depends on--type:-
remote→{ '<project>': './remoteEntry.json' } -
host→ an inline remote map derived from the workspace's other projects -
dynamic-host→ the path to a generatedfederation.manifest.json
@softarc/native-federation-orchestrator) by default —initFederation(<arg>, { ...useShimImportMap({ shimMode: true }), logger: consoleLogger, storage: globalThisStorageEntry, hostRemoteEntry: './remoteEntry.json', logLevel: 'debug' }). See Runtime. -
-
SSR. If the project has SSR enabled (
build.options.ssr.entryis set), the schematic also rewritesmain.server.tstobootstrap-server.ts+ a federation-awaremain.server.tsthat callsinitNodeFederation, and addscors+@softarc/native-federation-nodeto dependencies. -
federation.manifest.json. For dynamic hosts,
generates a manifest file. It lives in
public/federation.manifest.jsonif the project has apublic/folder, elsesrc/assets/federation.manifest.json. -
Dependencies. Adds
es-module-shims,@angular-devkit/build-angularand@softarc/native-federation-orchestrator(as a devDependency). Triggersnpm installat the end.
What it does NOT do
-
It does not add lazy routes to your shell — wire
loadRemoteModulein yourapp.routes.tsmanually (see Getting Started → step 4). -
It does not change your application code; only the bootstrap files
(
main.ts, optionallymain.server.ts) are touched.
appbuilder
ng g @angular-architects/native-federation-v4:appbuilder --project <name>
Migrates a project from the legacy
@angular-devkit/build-angular:browser-esbuild to the
modern @angular/build:application Application Builder.
Required to use any version of the adapter from 17.1 onward.
It only touches angular.json:
-
Switches the
esbuildtarget's builder to@angular/build:application. -
Renames the
mainoption tobrowser(the new builder's spelling). -
Rewrites the
serve-originaltarget'sbuildTargetvalues from:build:to:esbuild:, and the federationservetarget from:esbuild:back to:serve-original:.
update-v4
ng g @angular-architects/native-federation-v4:update-v4 [--project <name>] [--orchestrator]
Migrates a v3 project (CommonJS, legacy runtime) to v4 (full ESM,
optional orchestrator). --project is optional — omit it
to migrate every project in the workspace. The schematic is also wired
into ng update's migration collection, so
ng update picks it up automatically when you bump to a v4
release.
It performs:
-
Renames every
@angular-architects/native-federation:buildreference inangular.jsonto@angular-architects/native-federation-v4:build; ensures every federation target hasentryPoints(defaulting to<sourceRoot>/main.ts) andprojectNameset. -
For every project's
federation.config.js: rewrites from CommonJS to ESM (require()→import,module.exports = ...→export default ...), swaps@angular-architects/native-federationimports for@angular-architects/native-federation-v4, and renames the file tofederation.config.mjs. -
Updates
main.tsimports from@angular-architects/native-federationto@softarc/native-federation-runtime.
If you pass --orchestrator (or accept the prompt) it
additionally:
-
Adds
@softarc/native-federation-orchestrator(^4.0.0) todependencies. -
Surgically rewrites
initFederation(...)to import from the orchestrator and pass the orchestrator's options block (useShimImportMap,consoleLogger,globalThisStorageEntry,hostRemoteEntry: './remoteEntry.json',logLevel: 'debug'). The existing first argument (manifest path, remote map, or{}) is preserved.
Not touched by this schematic: the root package.json's
"type": "module" and the v4 runtime/core packages — those
are workspace-level concerns handled by ng update itself.
See Migration to v4 for the full
walkthrough.
update18 (auto migration)
Legacy migration that shipped on the v3 line. Triggered automatically
by ng update @angular-architects/native-federation when
crossing version 18. It:
-
Removes the obsolete
postinstallhook that earlier versions injected intopackage.json. -
Patches
node_modules/@angular/build/package.jsonto expose theprivateentry point the adapter needs.
You don't run this one by hand — it's listed here for completeness.
remove
ng g @angular-architects/native-federation-v4:remove --project <name>
Reverts a project back to a plain Angular setup:
- Removes
es-module-shimsfrom polyfills. -
Restores the original
buildfrom theesbuildtarget and the originalservefromserve-original. -
Rewrites
buildTargetreferences back from:esbuild:to:build:. -
Removes
main.tsand renamesbootstrap.tsback tomain.ts.
The schematic does not delete
federation.config.mjs or
tsconfig.federation.json — clean those up by hand.
Nx Generator
nx g @angular-architects/native-federation-v4:native-federation --name=<name>
Adds a new Nx library project pre-wired to the federation
builder. It registers the project, scaffolds a starter
src/index.ts, and creates a build target
executor pointing at
@angular-architects/native-federation-v4:build.
| Option | Description |
|---|---|
--name |
Library name. Required. |
--directory |
Optional sub-directory under libs/. |
--tags |
Comma-separated Nx project tags. |
For application-shaped Nx projects, prefer ng add /
nx g @angular-architects/native-federation-v4:init — the
library generator is for shared, federation-aware code.
Related
- Getting Started — the happy path that uses these schematics.
-
Builder — what the
angular.jsonthe schematic generates actually does. -
Migration to v4 — manual migration
walkthrough complementing
update-v4.