← Engineering Workflow

ENGINEERING WORKFLOW · 73

Cloudflare Static Assets:Source 不是 Production,dist 才是部署 Artifact

Static site deployment 的核心不是「GitHub 直接變網站」,而是 source 經 build 產生 artifact,再由 deployment tool 上傳。Production serving 的是已部署 artifact,不是你尚未 build 的 working tree。

Learning outcomes

1. Build boundary

repository source
  ↓ npm run build
dist/
  ↓ artifact verification
wrangler deploy
  ↓
Cloudflare deployment
  ↓
public workers.dev

如果 build script 漏複製某課,source 裡有它也沒用;artifact 裡不存在,production 就無法服務。

2. Deployment config 指向 artifact

assets.directory
  = "./dist"

實際 config syntax 依 Wrangler 版本而定;核心是不讓 deploy tool 猜「哪個 directory 才是正式輸出」。

3. Canonical URL / redirect

/catalog.html
   ↓
/catalog

Static hosting 對 extensionless route、trailing slash、fallback 的規則可能不同。Smoke 應驗 production 真實 route,而不是只驗本機 file path。

4. Deployment version 是 release identity

commit SHA
  ↓
Actions run
  ↓
build artifact
  ↓
Cloudflare deployment version

這條 chain 讓你回答「線上現在是哪一版」。

5. Public smoke

curl -L   -o /dev/null   -w "%{http_code}"   https://example.workers.dev/catalog

Artifact check 驗 build output;public smoke 再驗 platform routing、deployment 與對外可達性。

Project checkpoint:Course Workspace v12

Git commit
  ↓
CI PASS
  ↓
dist exact-set verification
  ↓
manual deploy
  ↓
deployment version
  ↓
public smoke PASS

至此從 source 修改到 production evidence 成為完整工程閉環。

Debug evidence:GitHub main 更新但網站還是舊版

  1. Production workflow 是否真的部署 current SHA?
  2. dist 是否包含修改?
  3. Deployment version 是否更新?
  4. Public route 是否正確?
  5. 最後才考慮 client cache。

Knowledge check

  1. Source tree 與 dist artifact 差在哪?
  2. 為什麼 source 有檔不代表 production 有?
  3. Public smoke 和 artifact check 各驗哪層?
  4. 畫出 commit SHA 到 deployment version 的 evidence chain。