← Posts

Deploying Astro to Cloudflare Workers

A step-by-step guide for deploying an Astro static site to Cloudflare using Workers Builds (CI/CD).

by harutin

Overview

This post covers how to deploy an Astro static site to Cloudflare using Workers Builds.

Prerequisites

Step 1: Install Wrangler

pnpm add -D wrangler

Step 2: Configure wrangler.jsonc

Create a wrangler.jsonc file in your project root:

{
  "name": "your-project-name",
  "compatibility_date": "your-compatibility-date",
  "assets": {
    "directory": "./dist",
    "not_found_handling": "404-page"
  }
}

Key settings:

Step 3: Set Up Cloudflare Workers Builds

  1. Log in to the Cloudflare dashboard
  2. Navigate to Workers & PagesCreate
  3. Select Import a repository and connect your GitHub account
  4. Choose your Astro project repository

Step 4: Configure Build Settings

Set the following in the build configuration:

SettingValue
Build commandnpx astro build
Deploy commandnpx wrangler deploy

Step 5: Push to GitHub

When you push to GitHub, Cloudflare Workers will automatically build and deploy your site.

Your site will be available at your-project-name.workers.dev. That’s it!

References