ข้ามไปยังเนื้อหา

Deployment & Ecosystem

astro build สร้าง output ที่ deploy ได้ใน dist/ สิ่งที่อยู่ในนั้นขึ้นกับ rendering mode:

  • Staticdist/ เป็นโฟลเดอร์ของไฟล์ .html, CSS และ island JavaScript เป็นแค่ไฟล์
  • On-demand / hybriddist/ มี server entry ในรูปแบบที่ adapter ของคุณ target ด้วย (Cloudflare Worker, Node server, serverless function) พร้อม static asset

ต่อ type-checking เข้ากับ build เพื่อให้ type error หยุด deploy ที่ไม่ดี: astro check && astro build

การตัดสินใจ deploy ที่ใหญ่ที่สุดคือ static vs on-demand — ตัวเลือกนี้กำหนดว่าคุณ host ที่ไหน ได้:

StaticOn-demand (SSR)
Outputไฟล์ HTMLserver entry + assets
ต้องการstatic host / CDN อะไรก็ได้runtime (ผ่าน adapter)
HostCloudflare Pages, Netlify, GitHub Pages, S3, CDN อะไรก็ได้Cloudflare Workers, Node server, Vercel, Netlify Functions
เหมาะกับcontent ที่เหมือนกันสำหรับทุกคนข้อมูลต่อ request: auth, form, live data
Adapterไม่ต้องต้อง

เว็บ static ล้วน deploy ที่ไหนก็ได้ที่ serve ไฟล์ พอมี route ไหนเป็น on-demand (หรือใช้ server island หรือ Actions) คุณต้องตั้ง adapter ที่ตรงกัน — deploy โดยไม่มี adapter ก็เจอ error คลาสสิก “an adapter is required”

flowchart TB
  build["astro build"] --> static["Static: HTML files"]
  build --> ssr["On-demand: server entry + assets"]
  static --> cdn["any CDN / static host"]
  ssr --> runtime["adapter runtime: Workers, Node, serverless"]
build ไปได้ที่ไหนบ้าง

สอง config value ที่มักทำคนสะดุดตอน deploy:

  • site ต้องเป็น URL ที่ deploy จริง (เช่น https://example.com) sitemap, canonical tag และ RSS สร้าง absolute URL จากค่านี้ — site ผิด link ก็ผิด
  • base ต้องตรงกับ subpath ที่คุณถูก serve deploy ไป example.com/docs/ ก็ตั้ง base: '/docs' แล้วอ้าง internal link ด้วย base prefix serve ที่ domain root ก็ละไว้ base ที่ไม่ตรงเป็นสาเหตุปกติของ “CSS และ link ของเว็บที่ deploy 404 หมด” — asset ถูกหาที่ path ผิด

Astro เป็น content-first และ ecosystem ของตัวเองสะท้อนสิ่งนั้น:

  • Starlight — documentation-site framework ทางการที่สร้างบน Astro (คอร์สนี้ก็สร้างด้วย Starlight): sidebar, search, i18n และ dark mode มาในตัว
  • Integrations directory — catalog ขนาดใหญ่ของ integration ทางการและ community: UI framework, CMS connector, image service, analytics และ adapter สำหรับ host หลักทุกตัว
  • content-focused patterns — เมื่อรวมกับ content collection Astro เป็นตัวเลือกที่เหมาะสำหรับ blog, docs, marketing site และ headless-CMS front-end ที่คุณได้เว็บ static (หรือ hybrid) ที่เร็วพร้อม content ที่มี type

หยิบ framework อย่าง Starlight เมื่อตรงกับ use case ของคุณ แทนที่จะสร้าง docs infrastructure ใหม่ด้วยมือ — สัญชาตญาณ “compose อย่าสร้างใหม่” เดียวกันที่ไหลผ่าน Astro

เว็บ Astro ที่ static ล้วน deploy ที่ไหนได้?
adapter จำเป็นสำหรับ deploy เมื่อไร?
เว็บที่ deploy ใต้ example.com/docs/ มี CSS และ link คืน 404 หมด สาเหตุที่น่าจะเป็นคือ?
Starlight คืออะไร?