Deploy to Cloudflare Pages
About 792 wordsAbout 3 min
2026-08-31
This guide covers Cloudflare Pages platform configuration. For decisions on build locations and managing platform build commands, see Deployment Overview.
Requirements
- Source code is pushed to a GitHub or GitLab repository;
- A Cloudflare account (the free tier is fully sufficient);
siteis set to your production domain (editsrc/config/siteConfig.tsin single-repo mode, orconfig/site.yamlin the content repo).
Caution
You must create a Pages project, not a Worker. Selecting the Worker type causes builds to fail with __dirname is not defined.
Option 1: Git integration
Create Pages project
Log into the Cloudflare Dashboard and go to Workers & Pages -> Create -> Pages -> Connect to Git.

Select repository
Select your Git provider, grant permissions, and choose the Shirone repository.


Configure build parameters
Confirm the following build settings:

Setting Value Project name Custom name; determines the <name>.pages.devsubdomainProduction branch mainBuild command pnpm buildBuild output directory distAdd environment variables
Expand the environment variables section and configure the following:

Variable Value Purpose NODE_VERSION26Default build images bundle older Node versions PNPM_VERSION11.28.2Matches the pinned version in packageManagerGIT_TERMINAL_PROMPT0Prevents interactive credential prompts from stalling builds Dual-repo setups also require
CONTENT_REPO_URL, and optionallyCONTENT_REPO_REFwhen pinning a branch. See Content Sources.Deploy
Click Save and Deploy. Initial site builds take approximately 3 to 6 minutes.
Subsequent pushes to main trigger production deployments, while pushes to other branches generate preview deployments with isolated preview URLs.
Option 2: upload with Wrangler
Suitable when building locally or in external CI pipelines, without consuming Cloudflare Pages build minutes.
pnpm add -g wrangler
wrangler login
pnpm build
wrangler pages deploy dist --project-name=shirone-blogA Git project cannot accept CLI uploads
A Pages project can only use one distribution mode: connected Git repository with automatic builds, or Direct Upload for prebuilt files. Running wrangler pages deploy against a Git-connected project returns an error.
To upload files via CLI, create a separate Direct Upload project in the dashboard (without linking Git or specifying build commands) and point --project-name to it.
Create a Deploy Hook
To rebuild automatically after the content repo pushes, go to Settings -> Builds & deployments -> Deploy hooks, fill in a name (for example content-update), select the main branch, and click Add hook:

Copy the generated webhook URL once the hook is created:

Hand this URL to the deployment hooks workflow.
Custom domain
- Open your project page, navigate to Custom domains -> Set up a custom domain, and enter your domain;
- If your domain is managed under the same Cloudflare account, DNS records are added automatically. Otherwise, add a
CNAMErecord pointing to<name>.pages.devin your DNS provider; - SSL certificates are issued automatically once DNS records propagate.
Caching
Cloudflare's default caching rules fit static websites well: short caches for HTML to reflect content updates quickly, and long caches for fingerprinted assets. For fine-grained control, place a _headers file in public/:
/assets/*
Cache-Control: public, max-age=31536000, immutable
/pagefind/*
Cache-Control: public, max-age=86400Troubleshooting
Build fails withUnsupported engine
The NODE_VERSION=26 environment variable is missing, or the build command is not using pnpm. Ensure Build Command is set to pnpm build and set PNPM_VERSION=11.28.2. Node.js 26 no longer bundles corepack; do not use corepack enable in place of manual installation.
Build fails with__dirname is not defined
The project was accidentally created as a Cloudflare Worker. Delete the Worker, create a Pages project instead, and reconnect the Git repository.
Monthly build quota exceeded
Cloudflare's free plan provides 500 build minutes per month. GitHub Actions and Pages builds count separately. For frequent minor post revisions, batch commits or use Wrangler to upload prebuilt files directly.
High latency from mainland China
Cloudflare network routing from mainland China can fluctuate. If most of your readership is located there, consider evaluating EdgeOne Pages.
Next steps
- Deployment Overview: compare other hosting providers
- Deployment Hooks: trigger rebuilds via webhook after content updates
Copyright
Copyright Ownership:Dawn6666666
License under:Attribution 4.0 International (CC-BY-4.0)