我將 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 中的所有內容嗎?
uj5u.com熱心網友回復:
按照此處的建議,通過在我的模塊中使用靜態欄位來修復它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329311.html
