From 6247f396a6e38104768361f31e148de1b6f2ff46 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Tue, 22 Jul 2025 01:45:12 +0000 Subject: [PATCH] sync docs --- .../60-adapter-cloudflare.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md b/apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md index 2cd8fb8b5..1b0304b7f 100644 --- a/apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md +++ b/apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md @@ -26,6 +26,7 @@ export default { adapter: adapter({ // See below for an explanation of these options config: undefined, + workerScriptPath: undefined, platformProxy: { configPath: undefined, environment: undefined, @@ -47,6 +48,12 @@ export default { Path to your [Wrangler configuration file](https://developers.cloudflare.com/workers/wrangler/configuration/). 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. +### workerScriptPath + +Specifies the output path of the generated Worker script file (e.g. `.svelte-kit/cloudflare/_worker.js`). By default, the adapter relies on the `main` field in your Wrangler configuration file to determine the Worker entrypoint. Setting this option allows you to control where the adapter emits the compiled Worker script. + +This is useful when you want to define your own Worker entrypoint (e.g. `src/index.ts`) that imports and wraps the SvelteKit handler, making it easier to add custom Cloudflare Worker handlers such as fetch, scheduled, or queue. + ### platformProxy Preferences for the emulated `platform.env` local bindings. See the [getPlatformProxy](https://developers.cloudflare.com/workers/wrangler/api/#parameters-1) Wrangler API documentation for a full list of options. @@ -228,3 +235,58 @@ assets.binding = "ASSETS"+++ }+++ } ``` + +## Cloudflare Worker Handlers + +The `workerScriptPath` option allows you to control where the adapter outputs the compiled Worker script. + +By default, the Cloudflare adapter writes the compiled Worker to `.svelte-kit/cloudflare/_worker.js`, and this file is referenced as the `main` entry in your `wrangler.toml` or `wrangler.jsonc`. + +If you want to define your own custom Worker entrypoint (e.g. `src/index.ts`) to add additional handlers like `fetch`, `scheduled`, or `queue`, you can specify the generated script path using this option. + +### svelte.config.js + +```ts +/// file: svelte.config.js +import adapter from '@sveltejs/adapter-cloudflare'; + +export default { + kit: { +--- adapter: adapter()--- ++++ adapter: adapter({ + workerScriptPath: '.svelte-kit/cloudflare/_worker.js' + })+++ + } +}; +``` + +### wrangler.toml + +```toml +/// file: wrangler.toml +---main = ".svelte-kit/cloudflare/_worker.js"--- ++++main = "src/index.ts"+++ +``` + +### wrangler.jsonc + +```jsonc +/// file: wrangler.jsonc +{ +--- "main": ".svelte-kit/cloudflare/_worker.js",--- ++++ "main": "src/index.ts",+++ +} +``` + +### src/index.ts + +```ts +/// file: src/index.ts +import sveltekit from '../.svelte-kit/cloudflare/_worker.js'; + +export default { + async fetch(request, env, ctx) { + return sveltekit.fetch(request, env, ctx); + }, +} satisfies ExportedHandler; +``` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy