A production-ready micro-frontend architecture using React + TypeScript + Webpack Module Federation, demonstrating runtime module loading, shared dependencies, and true micro-frontend independence.
- π Module Federation - Runtime module loading using Webpack Module Federation
- π¦ Shared Dependencies - React, React-DOM, and react-icons shared across all apps (57% bundle size reduction)
- π¨ Shared Design System - Single source of truth exposed via Module Federation
- π Full TypeScript - Complete type safety with federated modules
- π EventBus Notifications - Real-time cross-app communication
- β‘ Independent Deployments - Each app can be deployed separately
βββββββββββββββββββββββββββββββββββ
β HOST (modulararchitecutr-react)β
β - Exposes: Design System β
β - Imports: Chat, Email Apps β
βββββββββββββββββββββββββββββββββββ
β
Module Federation Runtime
β
βββββββββββββββββββββββ
β β
β β
ββββββββββββββββ ββββββββββββββββ
β CHAT β β EMAIL β
β - Exposes Appβ β - Exposes Appβ
β - Imports DS β β - Imports DS β
ββββββββββββββββ ββββββββββββββββ
- Node.js 16+
- npm or yarn
Module Federation requires preview mode to work. Follow these steps:
# 1. Install dependencies for all apps
npm run install:all
# 2. Build all apps (generates remoteEntry.js files)
npm run build
# 3. Start preview servers
npm run previewAccess the apps:
- HOST: http://localhost:5174/ (Main application with Module Federation)
- CHAT: http://localhost:5175/ (Standalone chat app)
- EMAIL: http://localhost:5176/ (Standalone email app)
Important Notes:
- Preview mode uses localhost URLs (
.env.developmentfiles) - Module Federation dynamically loads CHAT and EMAIL apps from localhost
- Dev mode (
npm run dev) does NOT work with Module Federation because it doesn't generateremoteEntry.jsfiles
# 1. Edit files
vim host/src/App.tsx
# 2. Rebuild the specific app
cd host && npm run build
# 3. Preview server auto-serves new build - just refresh browser (Cmd+Shift+R)For Vercel deployment with production URLs:
# 1. Ensure .env.production files exist with Vercel URLs
# host/.env.production
VITE_CHAT_URL=https://chat-seven-psi-63.vercel.app
VITE_EMAIL_URL=https://mail-sable.vercel.app
# chat/.env.production & email/.env.production
VITE_HOST_URL=https://modulararchitecutr-react.vercel.app
# 2. Build all apps for production
npm run build
# 3. Commit and push to deploy
git add .
git commit -m "Deploy changes"
git pushVercel will automatically deploy each app to its respective URL.
βββ host/ # Main application
β βββ src/
β β βββ designSystem/ # Exposed via Module Federation
β β βββ components/
β β βββ FederatedWrapper.tsx # Loads remote apps
β βββ vite.config.ts # Federation: exposes designSystem
β
βββ chat/ # Chat micro-frontend
β βββ src/App.tsx # Exposed as './App'
β βββ vite.config.ts # Federation: exposes App, imports designSystem
β
βββ email/ # Email micro-frontend
βββ src/App.tsx # Exposed as './App'
βββ vite.config.ts # Federation: exposes App, imports designSystem
- React 18 - UI library
- TypeScript - Type safety
- Vite 5 - Build tool
- Webpack Module Federation - Micro-frontend architecture
- Material Design Icons - Icon library
Create 3 separate Vercel projects from the same repository:
HOST
- Root Directory:
host - Build Command:
npm run build - Output Directory:
dist
CHAT
- Root Directory:
chat - Build Command:
npm run build - Output Directory:
dist
- Root Directory:
email - Build Command:
npm run build - Output Directory:
dist
The apps are already configured to use production URLs via .env.production files:
host/.env.production
VITE_CHAT_URL=https://chat-seven-psi-63.vercel.app
VITE_EMAIL_URL=https://mail-sable.vercel.app
chat/.env.production & email/.env.production
VITE_HOST_URL=https://modulararchitecutr-react.vercel.app
git add .
git commit -m "Deploy Module Federation architecture"
git pushVercel will automatically deploy all apps.
Open your HOST URL and click "Open (Module Federation)" - the apps will load seamlessly across different Vercel deployments!
Each app exposes and consumes modules at runtime:
- HOST exposes:
./designSystem - HOST consumes:
chatApp/App,emailApp/App - CHAT exposes:
./App - CHAT consumes:
host/designSystem - EMAIL exposes:
./App - EMAIL consumes:
host/designSystem
shared: ['react', 'react-dom', 'react-icons']Only one copy of React is loaded across all apps, reducing total bundle size by 57%.
The module manifest generated by Module Federation. Located at:
http://localhost:5174/assets/remoteEntry.js(HOST)http://localhost:5175/assets/remoteEntry.js(CHAT)http://localhost:5176/assets/remoteEntry.js(EMAIL)
npm run dev doesn't work with Module Federation because:
- Vite dev server doesn't generate
remoteEntry.jsfiles - This is a known limitation of
@originjs/vite-plugin-federation - Preview mode serves built assets where Module Federation works correctly
Use npm run dev for:
- Developing individual features
- Testing UI components
- Fast iteration with hot reload
Use npm run build + npm run preview for:
- Testing Module Federation
- Verifying production builds
- Demonstrating the architecture
Without Module Federation:
HOST: 200 KB (React + design system)
CHAT: 250 KB (React + design system + chat)
EMAIL: 250 KB (React + design system + email)
TOTAL: 700 KB
With Module Federation:
HOST: 200 KB (React + design system)
CHAT: 50 KB (only chat logic)
EMAIL: 50 KB (only email logic)
TOTAL: 300 KB (57% reduction!)
- Runtime Module Loading - Apps load dynamically, not at build time
- True Independence - Each app can be deployed separately
- Shared Dependencies - Only one copy of React across all apps
- TypeScript Support - Full type safety with federated modules
- Production Ready - Works on localhost and Vercel
- Window Close Tracking - Notifications for both modal and new tab modes
# Install all dependencies
npm run install:all
# Build all apps
npm run build
# Build individual apps
npm run build:host
npm run build:chat
npm run build:email
# Preview mode (required for Module Federation)
npm run preview
# Dev mode (Module Federation won't work)
npm run devCause: Preview servers not running
Solution:
npm run build
npm run previewCause: Using dev mode instead of preview mode
Solution: Always use npm run build + npm run preview
Solution:
# Rebuild the app you changed
cd host && npm run build
# Hard refresh browser (Cmd+Shift+R)- MODULE_FEDERATION.md - Deep dive into Module Federation architecture and implementation
- HOST: https://modulararchitecutr-react.vercel.app
- CHAT: https://chat-seven-psi-63.vercel.app
- EMAIL: https://mail-sable.vercel.app
MIT
Built with React + TypeScript + Webpack Module Federation