Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration

Step 1: Creare la Shell

Genera il progetto principale:

ng new shell-app –routing –style=scss

Aggiungi il supporto Module Federation:

ng add @angular-architects/module-federation –type host –port 4200


This content originally appeared on DEV Community and was authored by Federico

Step 1: Creare la Shell

Genera il progetto principale:

ng new shell-app --routing --style=scss

Aggiungi il supporto Module Federation:

ng add @angular-architects/module-federation --type host --port 4200

Esempio di configurazione webpack.config.js:

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

module.exports = {
  output: {
    publicPath: "http://localhost:4200/",
    uniqueName: "shell"
  },
  optimization: {
    runtimeChunk: false
  },
  plugins: [
    new ModuleFederationPlugin({
      name: "shell",
      remotes: {
        mfeProduct: "mfeProduct@http://localhost:4201/remoteEntry.js",
        mfeProfile: "mfeProfile@http://localhost:4202/remoteEntry.js"
      },
      shared: {
        "@angular/core": { singleton: true, strictVersion: true },
        "@angular/common": { singleton: true, strictVersion: true },
        "@angular/router": { singleton: true, strictVersion: true }
      }
    })
  ]
};

Step 2: Creare un Remote

Genera un'app remota:

ng new mfe-product --routing --style=scss

Configura webpack.config.js:

new ModuleFederationPlugin({
  name: "mfeProduct",
  filename: "remoteEntry.js",
  exposes: {
    "./ProductModule": "./src/app/product/product.module.ts"
  },
  shared: {
    "@angular/core": { singleton: true, strictVersion: true },
    "@angular/common": { singleton: true, strictVersion: true }
  }
});

Step 3: Caricamento Dinamico (Runtime Integration)

Usa il helper loadRemoteModule:

import { loadRemoteModule } from '@angular-architects/module-federation';

export const routes: Routes = [
  {
    path: 'product',
    loadChildren: () =>
      loadRemoteModule({
        remoteEntry: 'http://localhost:4201/remoteEntry.js',
        remoteName: 'mfeProduct',
        exposedModule: './ProductModule'
      }).then(m => m.ProductModule)
  }
];

Best Practice

  • Standalone Components: Angular 19 supporta componenti standalone, riducendo la complessità dei moduli.
  • Shared Dependencies: Usa singleton: true per Angular core/common/router.
  • Errori comuni: Evita di condividere Angular come peerDependency (può causare NG0200 Circular DI).
  • Nx Monorepo: Per team grandi, Nx semplifica la gestione di più MFE con caching e generators.

Conclusione

Con Angular 19 e Module Federation puoi creare architetture scalabili, modulari e indipendenti. Questo setup permette:

  • Deploy indipendenti.
  • Aggiornamenti rapidi.
  • Riduzione dei conflitti tra team.


This content originally appeared on DEV Community and was authored by Federico


Print Share Comment Cite Upload Translate Updates
APA

Federico | Sciencx (2025-11-08T00:53:52+00:00) Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration. Retrieved from https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/

MLA
" » Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration." Federico | Sciencx - Saturday November 8, 2025, https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/
HARVARD
Federico | Sciencx Saturday November 8, 2025 » Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration., viewed ,<https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/>
VANCOUVER
Federico | Sciencx - » Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/
CHICAGO
" » Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration." Federico | Sciencx - Accessed . https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/
IEEE
" » Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration." Federico | Sciencx [Online]. Available: https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/. [Accessed: ]
rf:citation
» Implementare Micro Frontend con Angular 19 e Module Federation: Shell + Runtime Integration | Federico | Sciencx | https://www.scien.cx/2025/11/08/implementare-micro-frontend-con-angular-19-e-module-federation-shell-runtime-integration/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.