Cloudflare Deploy
Deploy your VitePress documentation site to Cloudflare Pages for free, with automatic CI/CD through GitHub Actions.
Why Cloudflare Pages?
Cloudflare Pages offers several advantages for documentation sites:
- Free tier — unlimited bandwidth, 500 builds/month
- Global CDN — content served from 300+ locations worldwide
- Fast deploys — builds complete in under 60 seconds
- Automatic HTTPS — SSL certificates provisioned automatically
- Preview deploys — every pull request gets a preview URL
- Custom domains — connect your own domain for free
Deployment Methods
Method 1: GitHub Integration (Recommended)
The easiest method — connect your GitHub repo to Cloudflare Pages:
- Push your code to GitHub
- Go to Cloudflare Pages Dashboard
- Click "Create a project"
- Select "Connect to Git"
- Choose your GitHub repository
- Configure build settings:
| Setting | Value |
|---|---|
| Build command | npm run docs:build |
| Build output directory | docs/.vitepress/dist |
| Root directory | / |
- Click "Save and Deploy"
Method 2: GitHub Actions (Recommended for CI/CD)
For automatic deployments on every push, use GitHub Actions:
Step 1: Create Workflow File
Create .github/workflows/deploy.yml:
yaml
name: Deploy to Cloudflare Pages
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- run: npm ci
- run: npm run docs:build
- uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy docs/.vitepress/dist --project-name=your-project-nameStep 2: Set GitHub Secrets
In your GitHub repository, go to Settings > Secrets and variables > Actions and add:
CLOUDFLARE_API_TOKEN— your Cloudflare API tokenCLOUDFLARE_ACCOUNT_ID— your Cloudflare account ID
Step 3: Create Wrangler Config
Create wrangler.json:
json
{
"name": "my-docs",
"compatibility_date": "2025-08-15",
"pages_build_output_dir": "docs/.vitepress/dist",
"compatibility_flags": ["nodejs_compat"]
}Environment Variables on Cloudflare
To set environment variables (like API keys) on Cloudflare Pages:
- Go to your project in Cloudflare Pages Dashboard
- Navigate to Settings > Environment variables
- Click "Add variable"
- Enter the variable name and value
- Choose the environment (Production, Preview, or both)
TIP
For sensitive values like API keys, use the "Encrypt" option to store them as secrets.
Build Configuration Summary
| Setting | Value |
|---|---|
| Framework preset | None |
| Build command | npm run docs:build |
| Build output directory | docs/.vitepress/dist |
| Root directory | / |
| Node.js version | 22 |
Custom Domain
To connect a custom domain:
- Go to Cloudflare Pages > Custom domains
- Click "Set up a custom domain"
- Enter your domain name
- Follow the DNS configuration instructions
Troubleshooting
| Issue | Solution |
|---|---|
| Build fails | Check Node.js version (22+) and npm ci output |
| 404 on pages | Verify cleanUrls: true in config.js |
| Blank page | Check browser console for asset path errors |
| Stale content | Clear Cloudflare cache or redeploy |
| Slow builds | Enable cache: 'npm' in GitHub Actions |