recipe posted by John-Kim Murphy
Simple dual-deployment to Cloudflare (and Vercel/Netlify/etc)
Why? (Motivation)
- Perhaps you have a project deployed to Vercel, and you want to switch it to Cloudflare
- Or you have a project deployed to Cloudflare, and you want to switch to Vercel
- Or you just want to compare the performance of the same app on Cloudflare vs Netlify
Overview
There are two main ways to accomplish Cloudflare dual-deployments:
sv create, then modify for Cloudflare (this recipe focuses on this method)create-cloudflare, then modify for Vercel/Netlifly
The goal of both methods is to ensure four things:
svelte.config.jsis configured with@sveltejs/adapter-auto(to select the correct adapter at deployment)- The Cloudflare build ENV is set:
CF_PAGES=1(otherwiseadapter-autoselects the incorrect adapter) - A
wranger.tomlfile (tells Cloudflare's wrangler how to deploy the project) - An
.assetsignorefile (Cloudflare refuses to deploy if generated_worker.jsis a static asset)
Steps
npx sv createyour SvelteKit project.- Deploy to Vercel. (Works out of the box;
adapter-autois configured by default) - Add
wrangler.tomlto the root of your project - Deploy to Cloudflare.
- The build command must be
CF_PAGES=1 pnpm build && echo _worker.js > .svelte-kit/cloudflare/.assetsignore - Just
CF_PAGES=1 pnpm buildwill work if.assetsignorefile with_worker.jsis added tostaticfolder.
- The build command must be
Notes
- Don't forget to set your app's environment variables on each platform
- Vercel:
Setting > Environment Variables - Cloudflare:
Settings > Build > Variables and secrets(buildtime) and/orSettings > Variables and secrets(runtime)
- Vercel:
Sample wrangler.toml
name = "<NAME-OF-YOUR-PROJECT>"
compatibility_date = "2025-10-21" # Use the current date.
main = ".svelte-kit/cloudflare/_worker.js"
compatibility_flags = [ "nodejs_compat" ]
# Bind your static output directory (e.g. the client folder SvelteKit emitted)
[assets]
binding = "ASSETS"
directory = ".svelte-kit/cloudflare"