ng new microfrontend --create-application false
ng generate application shell --routing=true --style=scss
ng generate application home --routing=true --style=scss
ng generate application about --routing=true --style=scss
ng add @angular-architects/module-federation --project shell --port 5000
ng add @angular-architects/module-federation --project home --port 3000
ng add @angular-architects/module-federation --project about --port 4000
Shell App - webpack.config.js
...
remotes: {
"home": "http://localhost:3000/remoteEntry.js",
"about": "http://localhost:4000/remoteEntry.js",
},
...
Home/About App - webpack.config.js Exemplo home:
...
name: "home",
filename: "remoteEntry.js",
exposes: {
'./Module': './projects/home/src/app/home/home.module.ts',
},
...
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('home/Module').then((m) => m.HomeModule)
},{
path: 'about',
loadChildren: () => import('about/Module').then((m) => m.AboutModule)
},
];
'home/Module' e 'about/Module' não existem e o tsc irá reclamar. Criar arquivo no shell/src/decl.d.ts com a definição:
declare module 'home/Module';
declare module 'about/Module';
Precisa executar todos os projetos. Para isso, foi adicionado ao package.json a opção npm run run:all
A importação de módulo não pode ser Routes.forRoot. Erro de duplicidade. É necessário criar módulo dentro do remote e expô-lo.