我正在关注本教程,并尝试在 shell 和 mfe1 应用程序之间共享一个库。我在工作空间目录外创建了一个在 root 中注入的服务的 lib,然后将其添加到教程 package.json,并将其导入 shell 和 mfe1。在两个项目的 webpack 配置中,我添加了以下配置
new ModuleFederationPlugin({
.....
},
shared: {
.....
"my-lib": { singleton: true, strictVersion: true, requiredVersion: '1.0.0'},
...sharedMappings.getDescriptors()
}
}),
在测试 shell 时,我注意到单例服务被启动了两次,第一次是在加载 shell 时,第二次是在移动到 mfe1 时,也许我遗漏了一些东西,但 singleton: true
配置的目的不是确保该服务只有一个实例存在?