Module Federation allows a JavaScript application to dynamically load code from another application and in the process, share dependencies.
e.g.: Let application A use the Component1 of application B. Module Federation can make the Component1 like an independent resource and application A and application B use the same one.
js
// A
new ModuleFederationPlugin({
: "appA",
name: {
remotes: "appB",
appB
},: ["react", "react-dom"],
shared
});
// B
new ModuleFederationPlugin({
: "appB",
name: "remoteEntry.js",
filename: {
exposes: "./src/Component1",
Component1
},: ["react", "react-dom"],
shared
});
See: