How to set up remotes with @module-federation
instead of @nx/angular/mf
?
#30278
Unanswered
Chiorufarewerin
asked this question in
Questions
Replies: 1 comment
-
Hello // main.ts
import { init } from '@module-federation/enhanced/runtime';
fetch('/env.json')
.then((res) => res.json())
.then((res) => res.REMOTES)
.then((remotes: Record<string, string>) => Object.entries(remotes).map(([name, entry]) => ({ name, entry })))
.then((remotes) => init({ name: 'digital-app', remotes }))
.then(() => import('./bootstrap').catch((err) => console.error(err))); My env.json : {
"REMOTES": {
"remote-a": "http://localhost:4203/mf-manifest.json",
"remote-b": "http://localhost:4204/mf-manifest.json",
"remote-c": "http://localhost:4205/mf-manifest.json"
}
} And routes: // app.routes.ts
import { loadRemote } from '@module-federation/enhanced/runtime';
export const appRoutes: Route[] = [
{
path: 'route-a',
loadChildren: () => loadRemote<typeof import('remote-a/Routes')>('remote-a/Routes').then((m) => m!.remoteRoutes),
},
{
path: 'route-b',
loadChildren: () => loadRemote<typeof import('remote-b/Routes')>('remote-b/Routes').then((m) => m!.remoteRoutes),
},
] Hope it helps. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I don't have SSR, and the host initializes remotes dynamically.
main.ts
When I try to use
init
from@module-federation/enhanced/runtime
,I'm getting errors because I don't have Node.js at browser runtime:
Beta Was this translation helpful? Give feedback.
All reactions