Detailed Guide
Let's create a detailed guide on setting up a Monorepo with Module Federation for Micro Frontends using Nx. I'll break it down into simple steps, covering:
- Project Setup with Nx
- Creating Micro Frontend Apps
- Setting Up Module Federation
- Sharing Components & State
- Running & Deploying the Micro Frontends
Let me know if you'd like this guide in canvas mode for easy editing, or if you'd prefer me to share it here directly. π
Short Guide
Yes, when you create a host app and remote apps using Nx, they are automatically generated inside the apps/
folder.
Note
when we create or generate using npx create-nx-workspace@latest <Workspace name>
, then it will gives us list of action to perform. and if we select mono repo with js. it only then create apps/
directory or folder. otherwise it doesn't create apps
folder.
Here's how the file structure looks after running the commands:
β Folder Structure After Generating Host and Remote Apps
my-mfe-workspace/
βββ apps/
β βββ my-host/ π Host App (Main Shell)
β βββ my-remote1/ π Remote App 1
β βββ my-remote2/ π Remote App 2
βββ libs/ π (Optional for shared code)
βββ node_modules/
βββ nx.json
βββ package.json
βββ tsconfig.base.json
π Whatβs Inside Each App Folder?
Folder | Description |
---|---|
my-host |
The host app (main entry point). |
my-remote1 |
The first remote app. |
my-remote2 |
The second remote app. |
β How to Check the Installed Apps
To verify that the apps are installed, run:
π Ready to Run the Apps?
Now that the apps are created, you can serve them by running:
This will automatically start:
- The host app at
http://localhost:4200
. - The remote apps (
my-remote1
andmy-remote2
) on dynamic ports.