This adapter will be installed by default when you use adapter-auto. If you plan on staying with Cloudflare, you can switch from adapter-auto to using this adapter directly so that cloudflare:workers is emulated during local development, type declarations are automatically applied, and the ability to set Cloudflare-specific options is provided.
Comparisons
adapter-cloudflare – supports all SvelteKit features; builds for Cloudflare Workers Static Assets
adapter-cloudflare-workers – deprecated. Supports all SvelteKit features; builds for Cloudflare Workers Sites
adapter-static – only produces client-side static assets; compatible with Cloudflare Workers Static Assets and Cloudflare Pages
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
[!LEGACY]
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
[!LEGACY]
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Your adapter is run when executing vite build. It determines how the output is converted for different platforms.
undefined
:adapter(alias)adapter(options?:AdapterOptions):Adapterimportadapter({ // See below for an explanation of these options
config(property)AdapterOptions.config?:string|undefined
The path to the config file to use.
If no path is specified the default behavior is to search from the
current directory up the filesystem for a Wrangler configuration file to use.
Note: this field is optional but if a path is specified it must
point to a valid file on the filesystem
Indicates if and where to persist the bindings data, if not present or true it defaults to the same location
used by wrangler: .wrangler/state/v3 (so that the same data can be easily used by the caller and wrangler).
If false is specified no data is persisted on the filesystem.
Whether to render a plaintext 404.html page or a rendered SPA fallback page
for non-matching asset requests.
For Cloudflare Workers, the default behaviour is to return a null-body
404-status response for non-matching assets requests. However, if the
assets.not_found_handling
Wrangler configuration setting is set to "404-page", this page will be
served if a request fails to match an asset. If assets.not_found_handling
is set to "single-page-application", the adapter will render a SPA fallback
index.html page regardless of the fallback option specified.
'plaintext'
:'plaintext'})})]});
Options
config
Path to your Wrangler configuration file. If you would like to use a Wrangler configuration filename other than wrangler.jsonc, wrangler.json, or wrangler.toml you can specify it using this option.
platformProxy
Preferences for the emulated env local bindings. See the getPlatformProxy Wrangler API documentation for a full list of options.
fallback
Whether to render a plaintext 404.html page or a rendered SPA fallback page for non-matching asset requests.
For Cloudflare Workers, the default behaviour is to return a null-body 404-status response for non-matching assets requests. However, if the assets.not_found_handling Wrangler configuration setting is set to "404-page", this page will be served if a request fails to match an asset. If assets.not_found_handling is set to "single-page-application", the adapter will render a SPA fallback index.html page regardless of the fallback option specified.
Deployment
You can use the Wrangler CLI to deploy your application by running npx wrangler deploy or use the Cloudflare Git integration to enable automatic builds and deployments on push.
Runtime APIs
The env object contains your project’s bindings, which consist of KV/DO namespaces, etc. It is available on the cloudflare:workers module.
Cloudflare specific values are emulated during dev and preview modes. Local bindings are created based on your Wrangler configuration file and are used to populate env during development and preview. Use the adapter config platformProxy option to change your preferences for the bindings.
Durable Objects and Workflows, which require custom classes to be exported from your worker, are not currently supported.
For testing the build, you should use Wrangler version 4. Once you have built your site, run wrangler dev.
Headers and redirects
The _headers and _redirects files, specific to Cloudflare, can be used for static asset responses (like images) by putting them into the project root folder.
However, they will have no effect on responses dynamically rendered by SvelteKit, which should return custom headers or redirect responses from server endpoints or with the handle hook.
Troubleshooting
Worker size limits
Deploying your application will fail if your Worker files exceed the size limits after minification. You’re unlikely to hit this limit usually, but some large libraries can cause this to happen. In that case, you can try to reduce the size of your worker by only importing such libraries on the client side. See the FAQ for more information.
Accessing the file system
You can’t use fs in Cloudflare Workers.
Instead, use the read function from $app/server to access your files. It works by fetching the file from the deployed public assets location.
Alternatively, you can prerender the routes in question.
Migrating from Workers Sites
Cloudflare no longer recommends using Workers Sites and instead recommends using Workers Static Assets. To migrate, replace @sveltejs/adapter-cloudflare-workers with @sveltejs/adapter-cloudflare and remove main and all site configuration settings from your Wrangler configuration file.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
[!LEGACY]
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
Type helper to make it easier to use vite.config.ts
accepts a direct
{@link
UserConfig
}
object, or a function that returns it.
The function receives a
{@link
ConfigEnv
}
object.
As well as SvelteKit, the plugin options are used by other tooling that integrates with Svelte such as editor extensions.
Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte, so you can set options like inspector here too. The experimental namespace is shared — SvelteKit reads its own flags and forwards the rest.
[!LEGACY]
Prior to SvelteKit 3, config lived in a svelte.config.js file, which is no longer supported. The ability to configure SvelteKit via vite.config.js was added in version 2.62.
Remove pages_build_output_dir from your Wrangler configuration.
Remove the adapter’s routes option and any _routes.json files.
Replace wrangler pages dev and wrangler pages deploy with wrangler dev and wrangler deploy. For automatic deployments, use Workers Builds instead of the Pages Git integration.