Create a new Angular workspace with multiple applications (host + 2 remotes for demonstration):
bash
ng new mfe-demo --no-create-application --routing --style=scss --ssr=false
cd mfe-demo
ng generate application host --routing --style=scss
ng generate application remote1 --routing --style=scss
ng generate application remote2 --routing --style=scss
This creates:
host: The shell/host app that consumes remotes.
remote1: A remote micro-frontend exposing a component and route.
remote2: Another remote for demonstration.
Step 3: Install Module Federation Schematics
Install the official Angular Module Federation plugin (by Angular Architects):
bash
npm install --save-dev @angular-architects/module-federation @module-federation/webpack
ng add @angular-architects/module-federation --project host --port 4200
ng add @angular-architects/module-federation --project remote1 --port 4201 --type remote
ng add @angular-architects/module-federation --project remote2 --port 4202 --type remote
This auto-generates:
webpack.config.js in each app's root.
Updates angular.json for Module Federation builds.
A module-federation-config schematic setup.
Step 4: Configure the Remotes (Expose Modules)
remote1
Generate a simple component to expose:
bash
ng generate component featured --project remote1
Update projects/remote1/src/app/remote1.component.ts (rename default if needed):
Advanced: Use Nx for monorepo scaling, or deploy remotes to CDNs.
This is a fully functional, production-ready setup! Extend with auth, state sharing (e.g., via window), or Nx. Source: Official Angular Module Federation docs & Angular Architects guide.
config: {
name: 'host',
remotes: {
remote1: 'remote1@http://localhost:4201/remoteEntry.js',
remote2: 'remote2@http://localhost:4202/remoteEntry.js',
},
shared: { /* same as remotes */ },
}