Tue Sep 26 2023

Quick tip: Deploying a SvelteKit app in a Turborepo to Cloudflare Pages

This short article describes how to deploy a SvelteKit app inside a monorepo (using Turborepo) to Cloudflare pages.

To prepare your SvelteKit app for deployment to Cloudflare Pages you need to use the Cloudflare adapter. See the full description of how to configure your app in the official documentation.

When you have set up the app in the monorepo, you are ready to deploy it.

Create a new page under «Workers and Pages» in the Clouflare Dashboard. The config should be as follows:

I'm assuming that the SvelteKit app is called «web-sveltekit», update this as needed
  • Build command: npx turbo run build --filter=web-sveltekit...
  • Build output directory: /apps/web-sveltekit/.svelte-kit/cloudflare
  • Root directory: /

Cloudflare pages will detect your build system (yarn, npm, ..) and run the correct install command from the root of your project. It will then use turbo to run build for only your SvelteKit app (that's what the filter does). It then looks in the «build output directory» for the code to deploy.

That's it.