Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I reuse a MFE in another web app? #1

Open
HelloooJoe opened this issue Dec 10, 2021 · 1 comment
Open

How do I reuse a MFE in another web app? #1

HelloooJoe opened this issue Dec 10, 2021 · 1 comment

Comments

@HelloooJoe
Copy link

HelloooJoe commented Dec 10, 2021

Lets say I wanted to reuse the 'Menu' microfrontend inside another web app, how would I be able to do that with the module federation architecture?

Side note: I know if I use @angular/elements, in a normal Ng app, I can create a custom web component that I can then insert into another web app like so:
image

@jtneal
Copy link
Owner

jtneal commented Dec 10, 2021

With module federation, after you build your application, you'll get something like a remoteEntry.js file. This remote entry file is similar to your menu-mfe.js that you would have had in the web component approach. You would typically configure your host to load this file at runtime rather than placing it in your HTML like you've shown here.

This shows an example of loading the remote entry:
https://github.com/jtneal/ng-module-federation-demo/blob/main/src/main.ts#L6

This is where you can define routes pointing to the micro frontend:
https://github.com/jtneal/ng-module-federation-demo/blob/main/src/app/app-routing.module.ts#L6

The code I've linked above is using a package I wrote that wraps around another API just to make things a bit easier, but looking at the source may be beneficial. Here's a good article that shows the code:
https://www.angulararchitects.io/en/aktuelles/dynamic-module-federation-with-angular/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants