@angular-architects/native-federation-v4

中文文档
21.2.17发布于 2026/10/28MITTypeScriptES Module近 30 天下载 2.8万

npm version [npm downloads](http

原始使用文档
文档目录7 节
  1. Features
  2. Versions
  3. Quick start
  4. Documentation
  5. Contributing
  6. Credits
  7. License

@angular-architects/native-federation-v4

npm version npm downloads license

The Angular adapter for Native Federation: the mental model of Module Federation, implemented on browser standards (ES modules and import maps) for Micro Frontends and plugin-based architectures.

📖 Documentation

[!NOTE] This is the v4 bridge package for Angular 20 and 21. Upgrading from v3? See the migration guide, or run ng update @angular-architects/native-federation-v4. The v3 source lives in the module-federation-plugin repository.

Features

  • Stays on the Angular CLI — delegates to Angular's esbuild-based ApplicationBuilder and dev server, so you keep every CLI optimisation.
  • Web standards — remotes are plain ES modules wired together by an import map.
  • Shared dependencies — load a library once across host and remotes, with semver-aware version negotiation.
  • Schematics — ng add turns a project into a host or remote; ng update migrates it.
  • SSR, Incremental Hydration and I18N — supported out of the box.

Versions

The adapter follows Angular's version numbers: use the adapter release that matches your Angular major and minor (e.g. 21.2.x for Angular 21.2.x).

Your AngularInstall
22+@angular-architects/native-federation
20 – 21@angular-architects/native-federation-v4

@angular-architects/native-federation-v4 is a bridge package: it brings Native Federation v4 to projects still on Angular 20 or 21. Starting with Angular 22, v4 ships in the main @angular-architects/native-federation package again, so drop the -v4 suffix when you upgrade (ng update @angular-architects/native-federation does this for you).

Quick start

Install the adapter, then make one project a remote and another a host:

npm i @angular-architects/native-federation-v4 -D

ng g @angular-architects/native-federation-v4:init --project mfe1 --port 4201 --type remote
ng g @angular-architects/native-federation-v4:init --project shell --port 4200 --type dynamic-host

The schematic points angular.json at the federation builder, moves your bootstrap into bootstrap.ts and generates a federation.config.mjs:

import {
  withNativeFederation,
  fromPackageJson,
} from "@angular-architects/native-federation-v4/config";

export default withNativeFederation({
  name: "mfe1",
  exposes: {
    "./Component": "./projects/mfe1/src/app/app.component.ts",
  },
  shared: fromPackageJson({
    singleton: true,
    strictVersion: true,
    requiredVersion: "auto",
    build: "package",
  })
    // includeSecondaries is an opt-out of ignoreUnusedDeps, so every Angular
    // entrypoint is shared and builds can't publish different sets of them.
    .patch(["@angular/*"], { includeSecondaries: { keepAll: true } })
    .get(),
  skip: ["rxjs/ajax", "rxjs/fetch", "rxjs/testing", "rxjs/webSocket"],
  features: {
    denseChunking: true,
    denseExternals: true,
  },
});

Load the exposed component in the shell like any lazy route, then run ng serve mfe1 and ng serve shell. The Getting Started guide walks through every step, and the playground has runnable hosts, remotes and SSR examples.

Documentation

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, to the Angular CLI team, esp. Alan Agius and Charles Lyding, for the esbuild-based builder this adapter builds on, 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.

License

MIT

版本与发布记录

@angular-architects/native-federation-v4 共发布 44 个版本,首次发布于 2026/01/22;过去 12 个月发布了 44 个版本。

版本发布日期距今
21.2.17latest2026/10/2810 天前
21.2.162026/10/1820 天前
21.2.152026/10/031 个月前
21.2.142026/09/251 个月前
21.2.132026/09/241 个月前
21.2.122026/09/161 个月前

其他发布通道:v20-support → 20.4.3。

关于 @angular-architects/native-federation-v4 的常见问题

@angular-architects/native-federation-v4 是什么?

[](http

如何安装 @angular-architects/native-federation-v4?

在项目目录运行 npm install @angular-architects/native-federation-v4,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/build(>=21.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@angular-architects/native-federation-v4 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@angular-architects/native-federation-v4 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@angular-architects/native-federation-v4 可以商用吗?

@angular-architects/native-federation-v4 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@angular-architects/native-federation-v4 的下载量有多少?

根据 npm 官方下载统计,@angular-architects/native-federation-v4 在 2026/10/06 – 2026/11/04 这 30 天内被下载 27,798 次,日均约 927 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@angular-architects/native-federation-v4 还在维护吗?

最新版本 21.2.17 发布于 2026/10/28(10 天前);至今共发布 44 个版本,其中过去 12 个月发布了 44 个;首次发布于 2026/01/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。