使用 angular 在 webpack 联合上加载了错误的模块

汤伯里

我在端口 4200、4201 和 4202 上有 3 个应用程序。

在我的第一个应用程序(在 4200 上)上,我有一条通往其他应用程序的路由,这些应用程序加载了相应的模块,一个 ProfileModule,我正在根据该模块的导出组件创建组件。请注意,我的应用程序具有相同的模块和导出的组件名称。

这工作得很好,但出于某种原因,当我将我的路由从一个应用程序更改为另一个应用程序时,当组件已经加载一次时,webpack 会检索错误的模块。

在此处输入图片说明

我在这里做的是:

  1. 我正在路由到我的第二个应用程序(在 4201 上),它从第二个应用程序加载我的 ProfileModule
  2. 我正在路由到我的第三个应用程序(在 4202 上),它从第三个应用程序加载我的 ProfileModule
  3. 我要回到我的第二个应用程序,它从第三个应用程序而不是第二个应用程序加载我的 ProfileModule

我想这是由于模块名称,但如果它在不同的遥控器上不应该工作吗?

这是我获取模块的方式:

async function lookupExposedModule<T>(
  remoteName: string,
  exposedModule: string
): Promise<T> {
  // Initializes the share scope. This fills it with known provided modules from this build and all remotes
  await __webpack_init_sharing__("default");
  const container = window[remoteName] as Container; // or get the container somewhere else
  // Initialize the container, it may provide shared modules
  await container.init(__webpack_share_scopes__.default);
  const factory = await container.get(exposedModule);
  const Module = factory();
  return Module as T;
}

 

汤伯里

我在这里找到了解决方案

但就我而言,我的 webpack 配置中有不同遥控器的相同名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章