[英]How to use a federated React module if the host React application isn't using Webpack?
I have two React applications.我有两个 React 应用程序。 One is the remote app, and other is the host app.
一个是远程应用程序,另一个是主机应用程序。 The remote app uses Webpack 5 using which I have federated the module.
远程应用程序使用我已经联合模块的 Webpack 5。 The host app uses Rollup for all purposes.
主机应用程序将汇总用于所有目的。 I want the host application to use the federated module.
我希望主机应用程序使用联合模块。 How can I achieve this?
我怎样才能做到这一点?
The below is how we have exposed the remote app which is running on port 3000.下面是我们如何暴露在端口 3000 上运行的远程应用程序。
name: "ResetPassword",
filename: "remoteEntry.js",
remotes: {},
exposes: {
"./ResetPassword": "./src/pages/create-password",
},
shared: {
...packageJsonDeps,
react: { singleton: true, requiredVersion: packageJsonDeps.react },
"react-dom": { singleton: true, requiredVersion: packageJsonDeps["react-dom"] }
},
})
This official Module Federation example solves exactly this issue. 这个官方的 Module Federation 示例正好解决了这个问题。
Basically -基本上 -
remotes
.remotes
。shared
shared
Check this article for a simplistic walkthrough查看这篇文章以获得简单的演练
btw it's good practice to define the shared libraries/packages in your package.json something like顺便说一句,在 package.json 中定义共享库/包是一种很好的做法,例如
shared: require('../package.json').dependencies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.