Hint
Host app loads remote entry files at runtime and consumes exposed modules as if they were local — shared singleton deps avoid duplication
Module Federation (Webpack 5) lets a running application dynamically load code from another independently deployed app at runtime.
Key concepts:
remoteEntry.js file.// Remote webpack.config.js
plugins: [new ModuleFederationPlugin({
name: 'checkout',
filename: 'remoteEntry.js',
exposes: { './CheckoutApp': './src/CheckoutApp' },
shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
})]
// Host webpack.config.js
plugins: [new ModuleFederationPlugin({
remotes: { checkout: 'checkout@https://checkout.example.com/remoteEntry.js' },
shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
})]
// Host usage
const CheckoutApp = React.lazy(() => import('checkout/CheckoutApp'));
Runtime behaviour: the host downloads remoteEntry.js on demand, negotiates shared module versions, and loads only what's needed.