【发布时间】:2021-03-12 16:12:34
【问题描述】:
我在端口 4200、4201 和 4202 上有 3 个应用程序。
在我的第一个应用程序(在 4200 上)上,我有一条通往其他应用程序的路由,该应用程序加载了它们的相应模块 ProfileModule,并且我正在基于此模块的导出组件创建组件。 请注意,我的应用具有 same 模块和导出的组件名称。
这很好用,但是由于某种原因,当我将路由从一个应用更改到另一个应用时,当组件已经加载一次时,webpack 会检索错误的模块。
我在这里做的是:
- 我正在路由到我的第二个应用程序(在 4201 上),它从 second-app 加载我的 ProfileModule
- 我正在路由到我的第三个应用程序(在 4202 上),它从 third-app 加载我的 ProfileModule
- 我要回到我的第二个应用程序,它会从 third-app 而不是 second-app 加载我的 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;
}
【问题讨论】:
标签: javascript angular webpack