This project demonstrates the use of Module Federation with three separate applications:
- Host Application (React 16 with Webpack)
- Remote Application 1 (React 16 with Repack)
- Remote Application 2 (React 18 with Repack)
This demo showcases how Module Federation can be used to dynamically load components from different applications, even when they use different versions of React or different bundlers.
-
Host Application
- Uses React 16
- Bundled with Webpack
- Acts as the main application that consumes federated modules
-
Remote Application 1
- Uses React 16
- Bundled with Repack
- Exposes components to be used in the Host Application
-
Remote Application 2
- Uses React 18
- Bundled with Repack
- Exposes components to be used in the Host Application
- Node.js (version 14 or later recommended) for repack node 16
- npm or yarn
-
Clone the repository:
git clone https://github.com/yanirmanor/mf-multi-react.git cd module-federation-demo
-
Install dependencies for each application:
cd host && npm install cd ../remote1 && npm install cd ../remote2 && npm install
-
Start Remote Application 1:
cd remote18 npm start
-
Start Remote Application 2:
cd remote npm start
-
Start the Host Application:
cd host npm start
-
Open your browser and navigate to
http://localhost:3000
to see the Host Application.
module-federation-demo/
├── host/
│ ├── src/
│ ├── webpack.config.js
│ └── package.json
├── remote18/
│ ├── src/
│ ├── repack.config.js
│ └── package.json
├── remote/
│ ├── src/
│ ├── repack.config.js
│ └── package.json
└── README.md
Each application has its own configuration file:
- Host Application:
webpack.config.js
- Remote Application 1:
repack.config.js
- Remote Application 2:
repack.config.js
These files contain the Module Federation plugin configuration, defining which modules are exposed or consumed.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.