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
Copy file name to clipboardExpand all lines: documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Cloudflare Pages
4
4
5
5
To deploy to [Cloudflare Pages](https://developers.cloudflare.com/pages/), 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 type declarations will be automatically applied and you can set Cloudflare-specific options.
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 values specific to Cloudflare Workers are 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
@@ -57,9 +57,9 @@ When configuring your project settings, you must use the following settings:
57
57
-**Build command** – `npm run build` or `vite build`
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/functions/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with `context`and `caches`, meaning that you can access it in hooks and endpoints:
62
+
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/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/handlers/fetch/#contextwaituntil), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), meaning that you can access it in hooks and endpoints:
> SvelteKit's built-in `$env` module should be preferred for environment variables.
72
72
73
-
To make these types available to your app, reference them in your `src/app.d.ts`:
73
+
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
74
74
75
75
```diff
76
76
/// file: src/app.d.ts
@@ -90,7 +90,9 @@ export {};
90
90
91
91
### Testing Locally
92
92
93
-
`platform.env` is only available in the final build and not in dev mode. For testing the build, you can use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler)**version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`. Ensure you have your [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml`.
93
+
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. The [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml` will be used to populate `platform.env` during local development.
94
+
95
+
For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler)**version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`.
Copy file name to clipboardExpand all lines: documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,9 +84,9 @@ If you would like to enable [Node.js compatibility](https://developers.cloudflar
84
84
compatibility_flags = [ "nodejs_compat" ]
85
85
```
86
86
87
-
## Bindings
87
+
## Runtime APIs
88
88
89
-
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/platform/environment-variables/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with `context`and `caches`, meaning that you can access it in hooks and endpoints:
89
+
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/pages/platform/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/handlers/fetch/#contextwaituntil), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), meaning that you can access it in hooks and endpoints:
> SvelteKit's built-in `$env` module should be preferred for environment variables.
99
99
100
-
To make these types available to your app, reference them in your `src/app.d.ts`:
100
+
To include type declarations for your bindings, reference them in your `src/app.d.ts`:
101
101
102
102
```diff
103
103
/// file: src/app.d.ts
@@ -117,7 +117,9 @@ export {};
117
117
118
118
### Testing Locally
119
119
120
-
`platform.env` is only available in the final build and not in dev mode. For testing the build, you can use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler). Once you have built your site, run `wrangler dev`. Ensure you have your [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml`. Wrangler version 3 is recommended.
120
+
Cloudflare Workers specific values in the `platform` property are emulated during dev and preview modes. The [bindings](https://developers.cloudflare.com/workers/wrangler/configuration/#bindings) in your `wrangler.toml` will be used to populate `platform.env` during local development.
121
+
122
+
For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler)**version 3**. Once you have built your site, run `wrangler dev`.
0 commit comments