@angular-architects/module-federation-tools

中文文档
22.0.0发布于 2026/09/11MITTypeScriptES Module近 30 天下载 8.4万

Add-on for @angular-architects/module-federation helping to reduce boiler plate code.

原始使用文档
文档目录14 节
  1. Features
  2. Examples
  3. Tutorial
  4. Providing a Web Component with Module Federation
  5. Exposing Micro Frontend as Web Component in Angular
  6. Exposing Web Component with other Frameworks like React
  7. Exposing Web Component-based Micro Frontend via Module Fede…
  8. Helper for Angular
  9. Routing to Web Components
  10. Important: Angular 13+
  11. Sub-Routes
  12. Directly Loading a Web Component via Module Federation
  13. Some Additional Details
  14. More about the underlying ideas

@angular-architects/module-federation-tools

Add-on for @angular-architects/module-federation helping to reduce boiler plate code.

The current release is focusing on combining web components with module federation for multi framework and multi version micro frontends:

Example

By compiling and loading these web components via module federation, we can share libraries like Angular if they use the same version. Otherwise, module federation would decide at runtime to load a dedicated version of the lib for the micro frontend in question:

Venn

This can help to balance the trade-off between bundle size and isolation of micro frontends.

Disclaimer: Multi-Framework and -Version Micro increase the overall complexity and call for some workarounds. This library tries to hide some of them.

Features

  • ✅ Minimal amount of helper functions to allow implementing multi-framework/ multi-version Micro Frontends with Module Federation
  • ✅ You don't need an additional meta-framework. Instead, you just use your framework of choice, e. g. Angular
  • ✅ Extension to @angular-architects/module-federation

Examples

Tutorial

Please find our tutorial here.

Providing a Web Component with Module Federation

This helper packages assumes that Micro Frontends are exposed as Web Components.

Exposing Micro Frontend as Web Component in Angular

To do this in Angular, install @angular/elements:

npm i @angular/elements

Then you can directly convert your AppComponent to a Web Component:

import { createCustomElement } from '@angular/elements';
[...]

@NgModule({
  [...]
  declarations: [
    AppComponent
  ],
  bootstrap: [] // No bootstrap components!
})
export class AppModule {
  constructor(private injector: Injector) {
  }

  ngDoBootstrap() {
    const ce = createCustomElement(AppComponent, {injector: this.injector});
    customElements.define('angular1-element', ce);
  }

}

Exposing Web Component with other Frameworks like React

If you framework doesn't directly support exposing your application as a web component, you can easily write a simple Wrapper around it. Basically, a web component -- to be more precise: a custom element -- is just an EcmaScript class extending HtmlElement and registered via customElements.register. Please find an example for React here.

Exposing Web Component-based Micro Frontend via Module Federation

Add @angular-architects/module-federation to your micro frontend:

ng add @angular-architects/module-federation

Make your webpack.config.js expose the whole bootstrap.ts that bootstraps your AppModule.

// webpack.config.js
name: "angular3",
library: { type: "var", name: "angular3" },
filename: "remoteEntry.js",
exposes: {
    './web-components': './src/bootstrap.ts',
},

If the file that bootstraps your applications is called differently, adjust these settings accordingly.

Helper for Angular

For enabling Angular for a multi version/ multi framework scenario, we need some helper functions. The easiest way to use them, is to bootstrap your Angular app with our bootstrap helper:

// main.ts
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { bootstrap } from '@angular-architects/module-federation-tools';

bootstrap(AppModule, {
  production: environment.production,
  appType: 'shell',
  // appType: 'microfrontend'
});

Use this bootstrap helper for both, your shell and your micro frontends!

Please make sure to set the appType to shell for your shell application and to microfrontend for your Micro Frontends.

Routing to Web Components

The WebComponentWrapper helps you to route to web components:

export const APP_ROUTES: Routes = [
    [...]
    {
        path: 'angular1',
        component: WebComponentWrapper,
        data: {
          remoteEntry: 'https://nice-grass-018f7d910.azurestaticapps.net/remoteEntry.js',
          remoteName: 'angular1',
          exposedModule: './web-components',
          elementName: 'angular1-element'
        } as WebComponentWrapperOptions
    },
    [...]
}

Important: Angular 13+

Beginning with Angular 13, the CLI is emitting EcmaScript modules. Hence, we need to adjust the usage of the WebComponentWrapper when loading a remote that has been created with the CLI 13 or higher. For this, set type to remote and skip the remoteName property (for Modules, we don't need a remoteName):

export const APP_ROUTES: Routes = [
    [...]
    {
        path: 'angular1',
        component: WebComponentWrapper,
        data: {
          type: 'module',
          remoteEntry: 'https://your-path/remoteEntry.js',
          exposedModule: './web-components',
          elementName: 'angular1-element'
        } as WebComponentWrapperOptions
    },
    [...]
}

Sub-Routes

If a web component has it's own router, you can use our UrlMatchers startsWith and endsWith to define, which part of the URL is intended for the shell and for the micro frontend:

// Shell
export const APP_ROUTES: Routes = [
    [...]
    {
        matcher: startsWith('angular3'),
        component: WebComponentWrapper,
        data: {
          remoteEntry: 'https://gray-river-0b8c23a10.azurestaticapps.net/remoteEntry.js',
          remoteName: 'angular3',
          exposedModule: './web-components',
          elementName: 'angular3-element'
        } as WebComponentWrapperOptions
    },
    [...]
}
// Micro Frontend
RouterModule.forRoot([
  { path: 'angular3/a', component: AComponent },
  { path: 'angular3/b', component: BComponent },

  // To prevent issues when routing to other micro frontends
  // a catch-all route should be defined
  { path: '**', component: EmptyComponent },
]);

Directly Loading a Web Component via Module Federation

The WebComponentWrapper can also be used as a traditional component:

<mft-wc-wrapper [options]="item"></mft-wc-wrapper>
item: WebComponentWrapperOptions = {
    remoteEntry: 'https://witty-wave-0a695f710.azurestaticapps.net/remoteEntry.js',
    remoteName: 'react',
    exposedModule: './web-components',
    elementName: 'react-element'
},

The optional properties props and events allow to defined properties and events for the web component:

props = {
  message: 'Hello from Shell',
};

events = {
  clicked: (event) => {
    console.debug('clicked!', event);
  },
};
<mft-wc-wrapper [options]="item" [props]="props" [events]="events"></mft-wc-wrapper>

Some Additional Details

In a multi version micro frontend strategy, it is important to load the zone.js bundle to the window object only once. Also, one need to make sure that only one instance of the ngZone is used by all the micro frontends.

If you share @angular/core and therefore also have one technical reference to the BrowserPlatform, that is used by more than one micro frondend, Angular's default setup is, to support only one platform instance per shared version. Be aware that you need to create multi platform instances in case of different versions, but also in case the version is the same, but @angular/core is not shared, but packed into the micro frontend's bundles directly (like in Angular's default way w/o module federation).

Naturally, such technical details are hard to get into. Therefore the bootstrap() function of this package helps to implement your multi version strategy w/o the need of implementing those low-level aspects on your own.

Some optional flags are offered to provide options for custom behavior of the bootstrap() function:

  • ngZoneSharing: false: Deactivate ngZone sharing in the window object (not recommended):

    bootstrap(AppModule, {
      production: environment.production,
      ngZoneSharing: false, // defaults to true
    });
    
  • platformSharing: false: Deactivate Platform sharing in the window object (not recommended):

    bootstrap(AppModule, {
      production: environment.production,
      platformSharing: false, // defaults to true
    });
    
    • Possible, if dependencies are not shared or each bootstrapped remote app uses a different version.
  • activeLegacyMode: false: Deactivates the legacy mode that provides backwards compatibility for Platform sharing:

    bootstrap(AppModule, {
      production: environment.production,
      activeLegacyMode: false, // defaults to true
    });
    
    • If all your micro frontends use @angular-architects/module-federation-tools in version ^12.6.0, ^13.1.0 or any newer major version you can switch off the legacy mode manually.
    • Those versions introduced new features on how to share the Platform in the window object.
    • This allows to use the bootstrap() function even in such cases, where the same version is packed into different micro frontend bundles.

More about the underlying ideas

Please find more information on the underlying ideas in this blog article.

版本与发布记录

@angular-architects/module-federation-tools 共发布 86 个版本,首次发布于 2021/05/19;过去 12 个月发布了 6 个版本。

版本发布日期距今
22.0.0latest2026/09/111 个月前
21.2.32026/09/111 个月前
22.0.0-next.1next2026/08/232 个月前
21.2.22026/03/207 个月前
21.2.12026/03/068 个月前
21.2.02026/03/048 个月前

其他发布通道:current → 14.2.3,next → 22.0.0-next.1。

关于 @angular-architects/module-federation-tools 的常见问题

@angular-architects/module-federation-tools 是什么?

Add-on for @angular-architects/module-federation helping to reduce boiler plate code.

如何安装 @angular-architects/module-federation-tools?

在项目目录运行 npm install @angular-architects/module-federation-tools,或使用 pnpm add / yarn add / bun add。

@angular-architects/module-federation-tools 支持 TypeScript 吗?

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

@angular-architects/module-federation-tools 支持 ESM 还是 CommonJS?

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

@angular-architects/module-federation-tools 可以商用吗?

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

@angular-architects/module-federation-tools 的下载量有多少?

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

@angular-architects/module-federation-tools 还在维护吗?

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