Deploying an Astro v6 site to Cloudflare Workers
This post corresponds to PR 2 in the build series.
What shipped
- Cloudflare Workers as the deployment target via
@astrojs/cloudflare- Upgraded to the Astro 6-era adapter (
@astrojs/cloudflare@13.x) to match Astro v6
- Upgraded to the Astro 6-era adapter (
output: "server"(while still prerendering content-driven routes)- Wrangler config aligned with Astro 6
main:@astrojs/cloudflare/entrypoints/serverassetsbinding: serve./diststatic assets alongside the Worker
- A working local lifecycle that matches production closely
astro dev+astro previewrunning on Cloudflare’sworkerdruntime
- A “boring” manual deploy path (
wrangler deploy)
Why
- Cloudflare is already the platform constraint for this series.
- Astro v6’s direction is explicitly “Workers-friendly”; I want to follow defaults.
- I want local development and preview to be as close to production as possible.
Notes / gotchas (worth calling out)
astro previewruns using Cloudflare’sworkerdruntime, which is the point: it’s close to production.- Static routes can still be prerendered even in server mode (
export const prerender = true).- Reference: Astro “Rendering modes” docs:
https://docs.astro.build/en/basics/rendering-modes/ - Error reference (why the export must be a simple static boolean):
https://docs.astro.build/en/reference/errors/invalid-prerender-export
- Reference: Astro “Rendering modes” docs:
- If you remove
prerenderfrom a content-driven dynamic route,getStaticPaths()can be ignored in server mode and you’ll hit runtime errors (we saw this happen and fixed it by re-enabling prerendering on/posts/[...id]).
How to run and deploy (for now)
- Local dev:
bun run dev - Local “production-ish” preview:
bun run preview - Deploy manually:
bun run deploy
Where this goes next (CI/CD)
- Later: auto-deploy to production from
main, and generate preview deploys for PRs/branches.
Links
- PR: https://github.com/gtwright/density-disk/pull/3
- Key files:
astro.config.mjswrangler.jsonc.dev.vars.example(optional local env template).gitignorepackage.json