MFE 三段式部署 additive upload entry swap sweep

Module Federation 部署的核心目的:讓部署過程**永遠不存在「指向不存在 chunk 的 remoteEntry.js」**的時間窗。

Step 1: Additive Upload   上傳新的 hashed chunks(不刪舊檔)
Step 2: Entry Swap        覆蓋 index.html 與 remoteEntry.js
Step 3: Sweep             清除已不在 manifest 中的舊 chunks

為什麼順序是這樣

步驟若順序錯誤會發生什麼
1 先上 chunks若先換 entry,新 entry 指向尚未存在的 chunk → 白畫面
2 換 entry這是「原子切換點」,新舊版本在這一刻交接
3 最後 sweep保護仍在頁面上的 in-flight user(見 MFE in-flight user 與 ChunkLoadError race)

保證

  • Step 2 之前的 user 手上舊 entry 引用的 chunks 仍完整
  • Step 2 之後的 user 拿到新 entry,引用 Step 1 已就位的 chunks
  • Step 3 只清「沒有任何 entry 會再引用」的孤兒檔

Sweep 通常搭配保留期(N 天或 N 個版本),進一步降低撞 404 機率。

相關