Adapter for building SvelteKit applications on Cloudflare Pages with Workers integration
npx @tessl/cli install tessl/npm-sveltejs--adapter-cloudflare@7.2.0The SvelteKit Adapter Cloudflare enables deployment of SvelteKit applications to Cloudflare's edge computing infrastructure. It supports both Cloudflare Workers with static assets and Cloudflare Pages with Workers integration, handling the complex build process to transform SvelteKit applications into formats compatible with Cloudflare's serverless environment.
npm install @sveltejs/adapter-cloudflareimport adapter from "@sveltejs/adapter-cloudflare";For TypeScript projects with type support:
import adapter, { AdapterOptions, RoutesJSONSpec } from "@sveltejs/adapter-cloudflare";// svelte.config.js
import adapter from "@sveltejs/adapter-cloudflare";
export default {
kit: {
adapter: adapter({
config: 'wrangler.toml',
fallback: 'plaintext',
routes: {
include: ['/*'],
exclude: ['<all>']
}
})
}
};The adapter is built around several key components:
Core adapter factory function and configuration options for customizing the build process and deployment behavior.
import { Adapter } from '@sveltejs/kit';
import { GetPlatformProxyOptions } from 'wrangler';
function adapter(options?: AdapterOptions): Adapter;
interface AdapterOptions {
config?: string;
fallback?: 'plaintext' | 'spa';
routes?: {
include?: string[];
exclude?: string[];
};
platformProxy?: GetPlatformProxyOptions;
}Cloudflare-specific platform context and runtime environment for SvelteKit applications.
import {
CacheStorage,
IncomingRequestCfProperties,
ExecutionContext
} from '@cloudflare/workers-types';
declare global {
namespace App {
interface Platform {
env: unknown;
ctx: ExecutionContext;
context: ExecutionContext; // deprecated
caches: CacheStorage;
cf?: IncomingRequestCfProperties;
}
}
}interface RoutesJSONSpec {
version: 1;
description: string;
include: string[];
exclude: string[];
}