Using cloudflare wrangler to deploy a pages project
Prerequisites and Setup
Install Node.js (v18+) and Wrangler, the official Cloudflare Developer Platform CLI. You can install Wrangler globally or run it via npx:
Authenticate Wrangler with your Cloudflare account:
This opens a browser window prompting you to authorize Wrangler with your Cloudflare credentials.Create the Pages Project
Create a named Pages project beforehand to define your production branch:
Deploy to Cloudflare Pages
Deploy your build directory using the wrangler pages deploy command:
# General syntax
wrangler pages deploy <OUTPUT_DIRECTORY> --project-name=<PROJECT_NAME>
# Example for a Vite/React build output to 'dist'
wrangler pages deploy dist --project-name=my-website
Common Deployment Flags
-
Target a specific branch (Preview vs Production):
Deploying to your designated production branch (e.g., main) publishes to your primary.pages.dev URL, while other branches generate unique preview URLs. -
Attach a commit message:
CI/CD and Headless Deployments
For automated pipelines (e.g., GitLab CI or GitHub Actions), bypass browser authentication by exporting environment variables with an API token created in your Cloudflare dashboard: