Angular模块联合单例服务多次启动

我正在关注本教程,并尝试在 shell 和 mfe1 应用程序之间共享一个库。我在工作区目录外创建了 lib,在 root 中注入了一项服务,然后将其添加到教程 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配置的目的不是为了确保只有该服务的一个实例存在?

以上是Angular模块联合单例服务多次启动的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>