Properties5
6Cloudflare Pages provides static hosting on their global edge network with generous free tier limits. Excellent performance worldwide with unlimited bandwidth.
Project Setup
- Go to dash.cloudflare.com and sign up
- Navigate to Workers & Pages
- Click Create application > Pages
- Connect your Git repository
Build Configuration
In the Cloudflare Pages dashboard:
| Setting | Value |
|---|---|
| Build command | npm run generate |
| Build output directory | .output/public |
| Node.js version | 20 |
Or create a wrangler.toml file:
name = "my-docs"
compatibility_date = "2024-01-01"
[site]
bucket = ".output/public"
Environment Variables
Set in Settings > Environment variables:
NODE_VERSION = 20
NUXT_APP_BASE_URL = /
NUXT_PUBLIC_SITE_URL = https://docs.example.com
Custom Domain
- Go to Custom domains
- Add your domain
- If domain is on Cloudflare:
- DNS is configured automatically
- If domain is elsewhere:
- Add CNAME record pointing to
*.pages.dev
- Add CNAME record pointing to
SSL is automatically provisioned.
Deployment
Automatic Deploys
Pushes to your connected branch trigger automatic builds.
Manual Deploy via CLI
# Install Wrangler
npm install -g wrangler
# Login
wrangler login
# Deploy
npm run generate
wrangler pages deploy .output/public
Direct Upload
- Run
npm run generatelocally - Go to Cloudflare Pages dashboard
- Click Create deployment
- Upload the
.output/publicfolder
Advanced Configuration
Headers
Create public/_headers:
/_nuxt/*
Cache-Control: public, max-age=31536000, immutable
/*
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Redirects
Create public/_redirects:
/old-page /new-page 301
/blog/* /posts/:splat 301
Functions
Add serverless functions in functions/:
// functions/api/hello.ts
export async function onRequest(context) {
return new Response('Hello!')
}
Free Tier Limits
Cloudflare Pages is generous:
| Feature | Limit |
|---|---|
| Sites | Unlimited |
| Bandwidth | Unlimited |
| Requests | Unlimited |
| Builds | 500/month |
| Concurrent builds | 1 |
| Build minutes | 500/month |
Troubleshooting
Build Failures
Check build logs in Deployments. Common issues:
- Node version not set (add
NODE_VERSIONenvironment variable) - Wrong build output directory (must be
.output/public) - Missing dependencies
Slow Builds
Cloudflare Pages doesn't cache node_modules between builds. Each build installs fresh. This is slower but more reliable.
404 on Subpages
Ensure all routes are pre-rendered. Cloudflare Pages serves static files only—no server-side rendering.
Check your build output has the expected HTML files:
ls -la .output/public/guide/