我将 Angular 与Webpack 5 Module Federation一起用于微前端。我有 2 个应用程序(我们称它们为 app1 和 app2),而我的主应用程序 app1 正在联合 app2 的组件。
在 app2 中,我的暴露组件由我的主模块导出,因此当我尝试联合某个组件时,我可以从模块的导出部分获取它。在开发模式下一切正常,我可以获得暴露的模块,检索导出的组件,然后使用组件工厂解析器在 app1 中我想要的位置创建它。
但是当我在生产环境中构建时(我使用 ng serve --prod 来重现 prod 环境并对其进行测试),我导出的组件消失了,但导入和提供程序却没有。这是我得到的模块:
MyApp2Module: class e
ɵfac: ƒ (t)
ɵinj:
imports: Array(1)
0: (12) [ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ, ƒ]
length: 1
[[Prototype]]: Array(0)
providers: [ƒ]
[[Prototype]]: Object
ɵmod:
bootstrap: []
declarations: []
exports: []
id: null
imports: []
schemas: null
transitiveCompileScopes: null
type: class e
[[Prototype]]: Object
如您所见,在 ɵmod 中,我没有导出的组件和声明,我希望在这里看到我的组件。我猜这是由于AOT 编译和优化,因为它在开发模式下工作。AOT 是否故意删除 ɵmod 中的所有内容?