Legacy RequireJS micro frontends on federated React
RequireJS micro frontends get their shared libraries from a common web package (CWP). This demo brings Module Federation to them progressively, with no rebuild of the widgets. The guide explains the setup.
The setup: widgets and the CWP
In a RequireJS micro frontend, each widget is built as an AMD bundle. Shared libraries
like React and the UI kit are built into a common web package (CWP). Widgets consume
the CWP through webpack externals, so every bundle asks for its libraries with
define(["react", "react-dom", "ui-kit"], ...).
The problem
A large enterprise builds up many widgets from many teams over time. They all depend on the same CWP. Updating a library version or adding a variant means every team must move together, which is near impossible. Module Federation solves this, but legacy widgets cannot use it. They also cannot all migrate in one shot.
The fix: federation, one piece at a time
The CWP becomes a FynApp. It installs React and the UI kit from npm at pinned versions, and serves them from federation under the AMD ids the widgets already ask for. A kernel add-on routes RequireJS to it. Each RequireJS context stays on the legacy CWP or moves to the federated one, with no rebuild. New FynApps run on the same page and share the CWP's React when their range matches.
Try it
- Pick the federated CWP release, then pick Legacy CWP or Federated CWP for each set. Each set is its own RequireJS context with the same widget bundles, which were built against React 18. The legacy CWP is the old setup: UMD React 18 files and
legacy-components/dist/ui-kit.js. CWP 3 and CWP 4 serve React 18 or React 19 and ui-kit from federation, as the Files fetched table shows. - Load Team C in a set. RequireJS fetches only
widget-c.jsand reuses the React that set already loaded. - Check the React instances table. Each row is one copy of React, the apps that use it, and how many times its file was fetched. Two federated sets share one copy. Two legacy sets get one copy each.
Set 1: unchanged webpack AMD bundles
Set 2: unchanged webpack AMD bundles
FynApps on the same page
Two ordinary FynApps that import esm-react through federation. They know
nothing about RequireJS or the legacy widgets.
React instances on this page
| React | loaded from | used by | files fetched |
|---|
Files fetched
| at | set | kind | file |
|---|
Dependency graph
Set 1
Set 2
AMD add-on metrics
amd.* entries from kernel telemetry. They are the input for generating
preload meta later.
| entry | set | id | route | deps | ms | url |
|---|