You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: deprecate adapter-cloudflare-workers in favour of adapter-cloudflare (#13634)
* merge adapters
* changeset
* it's valid to not specify a main entry if the user is only deploying static assets
* format
* adjust docs
* also use cf pages env var
* fix migration guide link
* try to fix doc build error
* Update index.d.ts
Co-authored-by: Ben McCann <[email protected]>
* Update kind-carrots-deliver.md
Co-authored-by: Ben McCann <[email protected]>
* validate assets key if main key is set
* delete adapter-cloudflare-workers
* adjust docs and workspace for removing cloudflare workers
* fix docs title
* clarify _routes.json belongs to cloudflare pages
* Update packages/adapter-cloudflare/src/worker.js
Co-authored-by: Ben McCann <[email protected]>
* changes according to feedback
* revert type change
* fix lock file
* fixes
* tests
* fix lockfile
* format
---------
Co-authored-by: Ben McCann <[email protected]>
To deploy to [Cloudflare Pages](https://pages.cloudflare.com/), use [`adapter-cloudflare`](https://github.com/sveltejs/kit/tree/main/packages/adapter-cloudflare).
5
+
To deploy to [Cloudflare Workers](https://workers.cloudflare.com/) or [Cloudflare Pages](https://pages.cloudflare.com/), use [`adapter-cloudflare`](https://github.com/sveltejs/kit/tree/main/packages/adapter-cloudflare).
6
6
7
-
This adapter will be installed by default when you use [`adapter-auto`](adapter-auto). If you plan on staying with Cloudflare Pages, you can switch from [`adapter-auto`](adapter-auto) to using this adapter directly so that `event.platform` is emulated during local development, type declarations are automatically applied, and the ability to set Cloudflare-specific options is provided.
7
+
This adapter will be installed by default when you use [`adapter-auto`](adapter-auto). If you plan on staying with Cloudflare, you can switch from [`adapter-auto`](adapter-auto) to using this adapter directly so that `event.platform` is emulated during local development, type declarations are automatically applied, and the ability to set Cloudflare-specific options is provided.
8
8
9
9
## Comparisons
10
10
11
-
-`adapter-cloudflare` – supports all SvelteKit features; builds for [Cloudflare Pages](https://blog.cloudflare.com/cloudflare-pages-goes-full-stack/)
12
-
-`adapter-cloudflare-workers` – supports all SvelteKit features; builds for Cloudflare Workers
13
-
-`adapter-static` – only produces client-side static assets; compatible with Cloudflare Pages
11
+
-`adapter-cloudflare` – supports all SvelteKit features; builds for Cloudflare Workers Static Assets and Cloudflare Pages
12
+
-`adapter-cloudflare-workers` – deprecated. Supports all SvelteKit features; builds for Cloudflare Workers Sites
13
+
-`adapter-static` – only produces client-side static assets; compatible with Cloudflare Workers Static Assets and Cloudflare Pages
14
14
15
15
## Usage
16
16
17
17
Install with `npm i -D @sveltejs/adapter-cloudflare`, then add the adapter to your `svelte.config.js`:
18
18
19
19
```js
20
-
// @errors: 2307
21
20
/// file: svelte.config.js
22
21
importadapterfrom'@sveltejs/adapter-cloudflare';
23
22
24
23
exportdefault {
25
24
kit: {
26
25
adapter:adapter({
27
26
// See below for an explanation of these options
28
-
routes: {
29
-
include: ['/*'],
30
-
exclude: ['<all>']
31
-
},
27
+
config:undefined,
32
28
platformProxy: {
33
29
configPath:undefined,
34
30
environment:undefined,
35
31
persist:undefined
32
+
},
33
+
fallback:'plaintext',
34
+
routes: {
35
+
include: ['/*'],
36
+
exclude: ['<all>']
36
37
}
37
38
})
38
39
}
@@ -41,9 +42,31 @@ export default {
41
42
42
43
## Options
43
44
45
+
### config
46
+
47
+
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.
48
+
49
+
### platformProxy
50
+
51
+
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.
52
+
53
+
### fallback
54
+
55
+
Whether to render a plaintext 404.html page or a rendered SPA fallback page for non-matching asset requests.
56
+
57
+
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`](https://developers.cloudflare.com/workers/static-assets/routing/#2-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.
58
+
59
+
For Cloudflare Pages, this page will only be served when a request that matches an entry in `routes.exclude` fails to match an asset.
60
+
61
+
Most of the time `plaintext` is sufficient, but if you are using `routes.exclude` to manually
62
+
exclude a set of prerendered pages without exceeding the 100 route limit, you may wish to
63
+
use `spa` instead to avoid showing an unstyled 404 page to users.
64
+
65
+
See Cloudflare Pages' [Not Found behaviour](https://developers.cloudflare.com/pages/configuration/serving-pages/#not-found-behavior) for more info.
66
+
44
67
### routes
45
68
46
-
Allows you to customise the [`_routes.json`](https://developers.cloudflare.com/pages/functions/routing/#create-a-_routesjson-file) file generated by `adapter-cloudflare`.
69
+
Only for Cloudflare Pages. Allows you to customise the [`_routes.json`](https://developers.cloudflare.com/pages/functions/routing/#create-a-_routesjson-file) file generated by `adapter-cloudflare`.
47
70
48
71
-`include` defines routes that will invoke a function, and defaults to `['/*']`
49
72
-`exclude` defines routes that will _not_ invoke a function — this is a faster and cheaper way to serve your app's static assets. This array can include the following special values:
@@ -54,23 +77,52 @@ Allows you to customise the [`_routes.json`](https://developers.cloudflare.com/p
54
77
55
78
You can have up to 100 `include` and `exclude` rules combined. Generally you can omit the `routes` options, but if (for example) your `<prerendered>` paths exceed that limit, you may find it helpful to manually create an `exclude` list that includes `'/articles/*'` instead of the auto-generated `['/articles/foo', '/articles/bar', '/articles/baz', ...]`.
56
79
57
-
### platformProxy
80
+
##Cloudflare Workers
58
81
59
-
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.
82
+
### Basic configuration
83
+
84
+
When building for Cloudflare Workers, this adapter expects to find a [Wrangler configuration file](https://developers.cloudflare.com/workers/configuration/sites/configuration/) in the project root. It should look something like this:
85
+
86
+
```jsonc
87
+
/// file: wrangler.jsonc
88
+
{
89
+
"name":"<any-name-you-want>",
90
+
"main":".svelte-kit/cloudflare/_worker.js",
91
+
"compatibility_date":"2025-01-01",
92
+
"assets": {
93
+
"binding":"ASSETS",
94
+
"directory":".svelte-kit/cloudflare",
95
+
}
96
+
}
97
+
```
98
+
99
+
### Deployment
100
+
101
+
Please follow the [framework guide](https://developers.cloudflare.com/workers/frameworks/framework-guides/svelte/) for Cloudflare Workers to begin.
102
+
103
+
## Cloudflare Pages
60
104
61
-
## Deployment
105
+
###Deployment
62
106
63
107
Please follow the [Get Started Guide](https://developers.cloudflare.com/pages/get-started/) for Cloudflare Pages to begin.
64
108
65
-
When configuring your project settings, you must use the following settings:
109
+
If you're using the [Git integration](https://developers.cloudflare.com/pages/get-started/git-integration/), your build settings should look like this:
66
110
67
111
-**Framework preset** – SvelteKit
68
112
-**Build command** – `npm run build` or `vite build`
You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit site on Cloudflare Pages](https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-kit-site/).
118
+
119
+
### Notes
120
+
121
+
Functions contained in the [`/functions` directory](https://developers.cloudflare.com/pages/functions/routing/) at the project's root will _not_ be included in the deployment. Instead, functions should be implemented as [server endpoints](routing#server) in your SvelteKit app, which is compiled to a [single `_worker.js` file](https://developers.cloudflare.com/pages/functions/advanced-mode/).
122
+
71
123
## Runtime APIs
72
124
73
-
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/functions/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:
125
+
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:
74
126
75
127
```js
76
128
// @errors: 7031
@@ -101,26 +153,20 @@ declare global {
101
153
export {};
102
154
```
103
155
104
-
### Testing Locally
156
+
### Testing locally
105
157
106
-
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. Local [bindings](https://developers.cloudflare.com/pages/functions/bindings/) are created based on your [Wrangler configuration file](https://developers.cloudflare.com/pages/functions/wrangler-configuration/#local-development) and are used to populate `platform.env` during development and preview. Use the adapter config [`platformProxy` option](#Options-platformProxy) to change your preferences for the bindings.
158
+
Cloudflare specific values in the `platform` property are emulated during dev and preview modes. Local [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) are created based on your [Wrangler configuration file](https://developers.cloudflare.com/workers/wrangler/) and are used to populate `platform.env` during development and preview. Use the adapter config [`platformProxy` option](#Options-platformProxy) to change your preferences for the bindings.
107
159
108
-
For testing the build, you should use [Wrangler](https://developers.cloudflare.com/workers/wrangler/)**version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`.
160
+
For testing the build, you should use [Wrangler](https://developers.cloudflare.com/workers/wrangler/)**version 4**. Once you have built your site, run `wrangler dev .svelte-kit/cloudflare` if you're testing for Cloudflare Workers or `wrangler pages dev .svelte-kit/cloudflare` for Cloudflare Pages.
109
161
110
-
## Notes
111
-
112
-
Functions contained in the [`/functions` directory](https://developers.cloudflare.com/pages/functions/routing/) at the project's root will _not_ be included in the deployment. Instead, functions should be implemented as [server endpoints](routing#server) in your SvelteKit app, which is compiled to a [single `_worker.js` file](https://developers.cloudflare.com/pages/functions/advanced-mode/).
162
+
## `_headers` and `_redirects`
113
163
114
-
The [`_headers`](https://developers.cloudflare.com/pages/configuration/headers/) and [`_redirects`](https://developers.cloudflare.com/pages/configuration/redirects/) files specific to Cloudflare Pages can be used for static asset responses (like images) by putting them into the project root folder.
164
+
The [`_headers`](https://developers.cloudflare.com/pages/configuration/headers/) and [`_redirects`](https://developers.cloudflare.com/pages/configuration/redirects/) files specific can be used for static asset responses (like images) by putting them into the project root folder.
115
165
116
166
However, they will have no effect on responses dynamically rendered by SvelteKit, which should return custom headers or redirect responses from [server endpoints](routing#server) or with the [`handle`](hooks#Server-hooks-handle) hook.
117
167
118
168
## Troubleshooting
119
169
120
-
### Further reading
121
-
122
-
You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit site](https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-kit-site/).
123
-
124
170
### Node.js compatibility
125
171
126
172
If you would like to enable [Node.js compatibility](https://developers.cloudflare.com/workers/runtime-apis/nodejs/), you can add the `nodejs_compat` compatibility flag to your Wrangler configuration file:
@@ -139,3 +185,45 @@ When deploying your application, the server generated by SvelteKit is bundled in
139
185
### Accessing the file system
140
186
141
187
You can't use `fs` in Cloudflare Workers — you must [prerender](page-options#prerender) the routes in question.
188
+
189
+
## Migrating from Workers Sites to Workers Static Assets
190
+
191
+
Cloudflare no longer recommends using [Workers Sites](https://developers.cloudflare.com/workers/configuration/sites/configuration/) and instead recommends using [Workers Static Assets](https://developers.cloudflare.com/workers/static-assets/). To migrate, replace `@sveltejs/adapter-cloudflare-workers` with `@sveltejs/adapter-cloudflare` and remove all `site` configuration settings from your Wrangler configuration file, then add the `assets.directory` and `assets.binding` configuration settings:
Copy file name to clipboardExpand all lines: documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
title: Cloudflare Workers
3
3
---
4
4
5
-
To deploy to [Cloudflare Workers](https://workers.cloudflare.com/), use [`adapter-cloudflare-workers`](https://github.com/sveltejs/kit/tree/main/packages/adapter-cloudflare-workers).
5
+
> [!NOTE]`adapter-cloudflare-workers` has been deprecated in favour of [`adapter-cloudflare`](adapter-cloudflare). We recommend using `adapter-cloudflare` to deploy to Cloudflare Workers with [Static Assets](https://developers.cloudflare.com/workers/static-assets/) since Cloudflare Workers Sites will be deprecated in favour of it.
6
6
7
-
> [!NOTE] Unless you have a specific reason to use `adapter-cloudflare-workers`, it's recommended that you use [`adapter-cloudflare`](adapter-cloudflare) instead. Both adapters have equivalent functionality, but Cloudflare Pages offers features like GitHub integration with automatic builds and deploys, preview deployments, instant rollback and so on.
7
+
To deploy to [Cloudflare Workers](https://workers.cloudflare.com/) with [Workers Sites](https://developers.cloudflare.com/workers/configuration/sites/), use `adapter-cloudflare-workers`.
8
8
9
9
## Usage
10
10
@@ -28,7 +28,7 @@ export default {
28
28
29
29
### config
30
30
31
-
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`, you can specify it using this option.
31
+
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.
32
32
33
33
### platformProxy
34
34
@@ -112,7 +112,7 @@ export {};
112
112
113
113
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. Local [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) are created based on your [Wrangler configuration file](https://developers.cloudflare.com/workers/wrangler/) and are used to populate `platform.env` during development and preview. Use the adapter config [`platformProxy` option](#Options-platformProxy) to change your preferences for the bindings.
114
114
115
-
For testing the build, you should use [Wrangler](https://developers.cloudflare.com/workers/wrangler/)**version 3**. Once you have built your site, run `wrangler dev`.
115
+
For testing the build, you should use [Wrangler](https://developers.cloudflare.com/workers/wrangler/)**version 4**. Once you have built your site, run `wrangler dev`.
0 commit comments