1 Star 0 Fork 0

Cai Yufu/module-federation-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Self-Healing Example

This example demos self-healing capabilities with Module Federation. app2 depends on and is expecting a shared dependency to be provided in app1.


In app2's webpack config we are expecting styled-components to be a shared dependency with the app1 host application.

// app1 webpack.config.js
new ModuleFederationPlugin({
    // ...
    shared: ["react", "react-dom"] // note lack of "styled-components"
}),
// app2 webpack.config.js
new ModuleFederationPlugin({
    // ...
    shared: ["react", "react-dom", "styled-components"],
}),

Running Demo

Run yarn start. This will build and serve both app1 and app2 on ports 3001 and 3002 respectively.

Notice that the button in both apps are the same even though the host app didn't provide styled-components as a dependency. If you open DevTools and checkout the "Network" tab you can see 2 requests were made to app2; the remote <Button /> component and the missing styled-components vendor code.

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cauu/module-federation-examples.git
git@gitee.com:cauu/module-federation-examples.git
cauu
module-federation-examples
module-federation-examples
master

搜索帮助