This is a little proof of concept that I built to learn more about micro front-ends and Webpack Module Federation, using React & TypeScript.
This project consists of 2 micro front-ends, and 2 apps which utilize components from the micro front-ends in different ways:
- micro1 exposes 2 components:
CardAlpha
andContactFormAlpha
- micro2 exposes 1 component:
ModalAlpha
- app1 shows a grid of contact info cards (
micro1/CardAlpha
), which trigger modals (micro2/ModalAlpha
) containing a dummy contact form (micro1/ContactFormAlpha
). - app2 shows a list of cards (
micro1/CardAlpha
), which trigger modals (micro2/ModalAlpha
) containing more details.
We are using styled-components to apply different themes to the micro front-ends on each app. This same concept could be implemented using Tailwind CSS as well.
This project uses NPM workspaces so all commands can be run at the root of the main project without needing to traverse the subfolders:
- Ensure you are using the right version of Node (v20) with
nvm use
- Install dependencies with
npm install --workspaces
After installing dependencies, you can start the entire demo with one command using concurrently:
npm run start-all
- app1 runs at http://localhost:3000
- app2 runs at http://localhost:3001
- micro1 runs at http://localhost:3030 (only used to expose components)
- micro2 runs at http://localhost:3031 (only used to expose components)
If you prefer starting each dev server individually:
- Start the micro1 dev server with:
npm run start-micro1
- Start the micro2 dev server with:
npm run start-micro2
- (Optional) Start the app1 dev server with
npm run start-app1
- (Optional) Start the app2 dev server with
npm run start-app2
This project could pretty easily be deployed to Jamstack hosting environments:
- Update the
remotes
the webpack configs for app1 & app2.- It would be a good idea to put these into environment variables.
- Build the packages:
- To build them all at once, run
npm run build-all
in the project root. - To build individually, run
npm run build
in each package folder. - Builds produce a
dist
folder in each package folder.
- To build them all at once, run