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"],
}),
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。