I was deploying a SvelteKit app to Cloudflare Pages and wanted to do it from the command line rather than connecting to GitHub. Wrangler makes this straightforward.

Why Cloudflare Pages over Vercel/Netlify Link to heading

I evaluated all three for hosting a SvelteKit app:

Vercel - Excellent Next.js integration, but I found the pricing confusing for non-hobby projects. The free tier is generous, but the jump to Pro felt steep for what we needed.

Netlify - Great developer experience, but build times felt slower and we’d be paying for bandwidth separately.

Cloudflare Pages - Fast global CDN (Cloudflare’s network is massive), generous free tier, and importantly: it integrates with Cloudflare Workers for serverless functions. Since we were already using Cloudflare for DNS and DDoS protection, it made sense to consolidate.

I also liked that Cloudflare Pages supports direct deployment without connecting to GitHub. This means I can deploy from CI, from my laptop, or from anywhere with the CLI.

My deployment workflow Link to heading

For production deployments:

  1. Create a PR with changes
  2. Push to GitHub (triggers preview deployment automatically)
  3. Review the preview URL in the PR
  4. Merge to main (triggers production deployment)

For quick fixes or testing:

  1. Make changes locally
  2. Build: npm run build
  3. Deploy directly: npx wrangler pages deploy

The direct deployment is great for emergency fixes when you don’t want to wait for GitHub Actions.

Setup Link to heading

Login first:

npx wrangler login

This opens a browser for OAuth.

Check you’re logged in:

npx wrangler whoami

Deploy Link to heading

For a SvelteKit app built with the Cloudflare adapter:

npx wrangler pages deploy .svelte-kit/cloudflare --project-name my-project

For a static site:

npx wrangler pages deploy ./dist --project-name my-project

First deploy Link to heading

If the project doesn’t exist yet, wrangler will ask if you want to create it. Just say yes and it’ll create the project in your Cloudflare account.

Production vs preview Link to heading

By default deploys go to a preview URL like abc123.my-project.pages.dev. This is great for testing before promoting to production.

To deploy directly to production:

npx wrangler pages deploy ./dist --project-name my-project --branch main

Or set the production branch in the Cloudflare dashboard and any deploy from that branch will automatically go to production.

In CI Link to heading

For GitHub Actions or other CI systems, create an API token in the Cloudflare dashboard and set it as CLOUDFLARE_API_TOKEN. Wrangler will use it automatically without the interactive login flow.

Example GitHub Actions workflow:

- name: Deploy to Cloudflare Pages
  run: npx wrangler pages deploy ./dist --project-name my-project
  env:
    CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

What I like about this workflow Link to heading

  • No vendor lock-in - I can deploy from anywhere, not just through GitHub
  • Fast deploys - Typically under 30 seconds from push to live
  • Preview URLs - Every branch gets its own URL automatically
  • Global CDN - Content is cached on Cloudflare’s massive network
  • Free tier is generous - 500 builds/month and unlimited bandwidth

The integration with Cloudflare Workers is the real killer feature though. You can add serverless functions to your Pages site trivially, which makes it more flexible than just a static host.

Further reading Link to heading