Module Federation lets you split a monolithic frontend into independently deployed micro-frontends. The pitch is compelling; the migration is not. Here is a path that avoids the big-bang rewrite.
Phase 1: Extract the shell
The shell is the layout (header, sidebar, footer) plus the router. Extract it into its own webpack build with Module Federation configured as the host:
// webpack.config.js (shell)
new ModuleFederationPlugin({
name: 'shell',
remotes: {
dashboard: 'dashboard@/remoteEntry.js',
},
})
The shell loads each micro-frontend lazily when its route is hit.
Phase 2: Strangler fig per route
Convert one route at a time. The monolith still serves unconverted routes; the shell delegates to it via an iframe or a redirect:
const Dashboard = React.lazy(() => import('dashboard/App'));
const LegacyPage = () => <iframe src="/legacy/settings" />;
This is ugly but lets you migrate over weeks, not months.
Phase 3: Shared dependencies
The biggest pitfall is duplicate React bundles. Declare shared dependencies:
shared: {
react: { singleton: true, requiredVersion: '^18.0.0' },
'react-dom': { singleton: true, requiredVersion: '^18.0.0' },
}
A multi-section platform like Voxcasino that ships separate teams' code as one site benefits most from this approach — each team deploys independently, and a broken deploy in one section does not take down the others.
Versioning contract
Each remote publishes a semver. The shell pins to major versions. A breaking change in a remote's exposed API bumps the major, and the shell must update its import before the old version is removed.
Takeaway
Module Federation is a deployment architecture, not a code architecture. The code stays clean React; only the build and routing layer changes. Migrate one route at a time and keep the monolith running until every route is extracted.
Top comments (0)