Source code of a remote module using Webpack Module Federation which is meant to be served locally to override the one used in a production app example.
Screen.Recording.2022-04-22.at.17.31.30.mov
It allows your developers/customers to develop remote modules locally without having to onboard them on your architecture and install it on their local machine. It can be also helpful to debug on a production/preproduction environment
- A static page working as a shell is served on the following URL -> https://mf-shell-local-override-typename.vercel.app/
- The shell retrieves a remote module named
Header
which is served here and which is used to display the header components. - Running this project, it will serve the same remote module under
http://localhost:1337/remoteEntry.js
that you can customize. - Using the integrated devtools on the bottom of the page you can override the
Header
remote module with the one you are serving locally. - Using
promise new Promise
from Module Federation it will look if there is a local override configuration from the localStorage and fetch the local one instead on runtime.
ℹ️ Makes sure you have installed Node >14.x with NPM (or Yarn)
npm install
or with yarn:
yarn
npm run start
or with yarn:
yarn start
ℹ️ remoteEntry.js
should be served on http://localhost:1337/remoteEntry.js
- Install and run this project
- Now that you are serving the remote module locally open the production example app
- Add in the URL the following query parameter
?inspect=true
- On the bottom of the page a black bar should appear, click on
Maximize
- On the
Local module name
input typeHeader
- On the
Local module URL
input typehttp://localhost:1337/remoteEntry.js
- Refresh the page and voilà! The title should now be
Local
instead ofDefault
For now we can only override a remote module that is already specified on the remotes list of the shell. In the future we'll be able to dynamically add a new remote module from localhost.
This can happen if you have enabled the web experimental features on Google Chrome flags