Skip to content

Commit 13c3bbb

Browse files
Sync kit docs (#1469)
sync kit docs Co-authored-by: svelte-docs-bot[bot] <196124396+svelte-docs-bot[bot]@users.noreply.github.com>
1 parent 8d6bd7e commit 13c3bbb

File tree

15 files changed

+163
-100
lines changed

15 files changed

+163
-100
lines changed

apps/svelte.dev/content/docs/kit/10-getting-started/30-project-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This file contains your Svelte and SvelteKit [configuration](configuration).
8080

8181
### tsconfig.json
8282

83-
This file (or `jsconfig.json`, if you prefer type-checked `.js` files over `.ts` files) configures TypeScript, if you added typechecking during `npx sv create`. Since SvelteKit relies on certain configuration being set a specific way, it generates its own `.svelte-kit/tsconfig.json` file which your own config `extends`.
83+
This file (or `jsconfig.json`, if you prefer type-checked `.js` files over `.ts` files) configures TypeScript, if you added typechecking during `npx sv create`. Since SvelteKit relies on certain configuration being set a specific way, it generates its own `.svelte-kit/tsconfig.json` file which your own config `extends`. To make changes to top-level options such as `include` and `exclude`, we recommend extending the generated config; see the [`typescript.config` setting](configuration#typescript) for more details.
8484

8585
### vite.config.js
8686

apps/svelte.dev/content/docs/kit/20-core-concepts/30-form-actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ Note that you need to `deserialize` the response before processing it further us
470470
If you have a `+server.js` alongside your `+page.server.js`, `fetch` requests will be routed there by default. To `POST` to an action in `+page.server.js` instead, use the custom `x-sveltekit-action` header:
471471
472472
```js
473+
// @errors: 2532 2304
473474
const response = await fetch(this.action, {
474475
method: 'POST',
475476
body: data,

apps/svelte.dev/content/docs/kit/20-core-concepts/60-remote-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default {
2626

2727
## Overview
2828

29-
Remote functions are exported from a `.remote.js` or `.remote.ts` file, and come in four flavours: `query`, `form`, `command` and `prerender`. On the client, the exported functions are transformed to `fetch` wrappers that invoke their counterparts on the server via a generated HTTP endpoint. Remote files must be placed in the `lib` or `routes` directory.
29+
Remote functions are exported from a `.remote.js` or `.remote.ts` file, and come in four flavours: `query`, `form`, `command` and `prerender`. On the client, the exported functions are transformed to `fetch` wrappers that invoke their counterparts on the server via a generated HTTP endpoint. Remote files must be placed in your `src` directory.
3030

3131
## query
3232

apps/svelte.dev/content/docs/kit/25-build-and-deploy/40-adapter-node.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Install with `npm i -D @sveltejs/adapter-node`, then add the adapter to your `sv
1414
/// file: svelte.config.js
1515
import adapter from '@sveltejs/adapter-node';
1616

17-
export default {
17+
/** @type {import('@sveltejs/kit').Config} */
18+
const config = {
1819
kit: {
1920
adapter: adapter()
2021
}
2122
};
23+
24+
export default config;
2225
```
2326

2427
## Deploying
@@ -147,7 +150,8 @@ The adapter can be configured with various options:
147150
/// file: svelte.config.js
148151
import adapter from '@sveltejs/adapter-node';
149152

150-
export default {
153+
/** @type {import('@sveltejs/kit').Config} */
154+
const config = {
151155
kit: {
152156
adapter: adapter({
153157
// default options are shown
@@ -157,6 +161,8 @@ export default {
157161
})
158162
}
159163
};
164+
165+
export default config;
160166
```
161167

162168
### out

apps/svelte.dev/content/docs/kit/25-build-and-deploy/50-adapter-static.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ This will prerender your entire site as a collection of static files. If you'd l
1212
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js`:
1313

1414
```js
15-
// @errors: 2307
1615
/// file: svelte.config.js
1716
import adapter from '@sveltejs/adapter-static';
1817

19-
export default {
18+
/** @type {import('@sveltejs/kit').Config} */
19+
const config = {
2020
kit: {
2121
adapter: adapter({
2222
// default options are shown. On some platforms
@@ -29,6 +29,8 @@ export default {
2929
})
3030
}
3131
};
32+
33+
export default config;
3234
```
3335

3436
...and add the [`prerender`](page-options#prerender) option to your root layout:
@@ -50,13 +52,17 @@ Some platforms have zero-config support (more to come in future):
5052
On these platforms, you should omit the adapter options so that `adapter-static` can provide the optimal configuration:
5153

5254
```js
53-
// @errors: 2304
5455
/// file: svelte.config.js
55-
export default {
56+
import adapter from '@sveltejs/adapter-static';
57+
58+
/** @type {import('@sveltejs/kit').Config} */
59+
const config = {
5660
kit: {
5761
adapter: adapter(---{...}---)
5862
}
5963
};
64+
65+
export default config;
6066
```
6167

6268
## Options
@@ -90,7 +96,7 @@ You'll also want to generate a fallback `404.html` page to replace the default 4
9096
A config for GitHub Pages might look like the following:
9197

9298
```js
93-
// @errors: 2307 2322
99+
// @errors: 2322
94100
/// file: svelte.config.js
95101
import adapter from '@sveltejs/adapter-static';
96102

apps/svelte.dev/content/docs/kit/25-build-and-deploy/55-single-page-apps.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ If you don't have any server-side logic (i.e. `+page.server.js`, `+layout.server
1919
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js` with the following options:
2020

2121
```js
22-
// @errors: 2307
2322
/// file: svelte.config.js
2423
import adapter from '@sveltejs/adapter-static';
2524

26-
export default {
25+
/** @type {import('@sveltejs/kit').Config} */
26+
const config = {
2727
kit: {
2828
adapter: adapter({
2929
fallback: '200.html' // may differ from host to host
3030
})
3131
}
3232
};
33+
34+
export default config;
3335
```
3436

3537
The `fallback` page is an HTML page created by SvelteKit from your page template (e.g. `app.html`) that loads your app and navigates to the correct route. For example [Surge](https://surge.sh/help/adding-a-200-page-for-client-side-routing), a static web host, lets you add a `200.html` file that will handle any requests that don't correspond to static assets or prerendered pages.

apps/svelte.dev/content/docs/kit/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Install with `npm i -D @sveltejs/adapter-cloudflare`, then add the adapter to yo
2121
/// file: svelte.config.js
2222
import adapter from '@sveltejs/adapter-cloudflare';
2323

24-
export default {
24+
/** @type {import('@sveltejs/kit').Config} */
25+
const config = {
2526
kit: {
2627
adapter: adapter({
2728
// See below for an explanation of these options
@@ -39,6 +40,8 @@ export default {
3940
})
4041
}
4142
};
43+
44+
export default config;
4245
```
4346

4447
## Options
@@ -126,9 +129,25 @@ Functions contained in the [`/functions` directory](https://developers.cloudflar
126129
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 [`ctx`](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:
127130

128131
```js
129-
// @errors: 7031
132+
// @filename: ambient.d.ts
133+
import { DurableObjectNamespace } from '@cloudflare/workers-types';
134+
135+
declare global {
136+
namespace App {
137+
interface Platform {
138+
env: {
139+
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
140+
};
141+
}
142+
}
143+
}
144+
// @filename: +server.js
145+
// ---cut---
146+
// @errors: 2355 2322
147+
/// file: +server.js
148+
/** @type {import('./$types').RequestHandler} */
130149
export async function POST({ request, platform }) {
131-
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
150+
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
132151
}
133152
```
134153
@@ -143,7 +162,7 @@ To make these types available to your app, install [`@cloudflare/workers-types`]
143162
declare global {
144163
namespace App {
145164
interface Platform {
146-
+++ env?: {
165+
+++ env: {
147166
YOUR_KV_NAMESPACE: KVNamespace;
148167
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
149168
};+++
@@ -198,15 +217,19 @@ Cloudflare no longer recommends using [Workers Sites](https://developers.cloudfl
198217
### svelte.config.js
199218
200219
```js
220+
// @errors: 2307
201221
/// file: svelte.config.js
202222
---import adapter from '@sveltejs/adapter-cloudflare-workers';---
203223
+++import adapter from '@sveltejs/adapter-cloudflare';+++
204224

205-
export default {
225+
/** @type {import('@sveltejs/kit').Config} */
226+
const config = {
206227
kit: {
207228
adapter: adapter()
208229
}
209230
};
231+
232+
export default config;
210233
```
211234
212235
### wrangler.toml

apps/svelte.dev/content/docs/kit/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ Install with `npm i -D @sveltejs/adapter-cloudflare-workers`, then add the adapt
1616
/// file: svelte.config.js
1717
import adapter from '@sveltejs/adapter-cloudflare-workers';
1818

19-
export default {
19+
/** @type {import('@sveltejs/kit').Config} */
20+
const config = {
2021
kit: {
2122
adapter: adapter({
2223
// see below for options that can be set here
2324
})
2425
}
2526
};
27+
28+
export default config;
2629
```
2730

2831
## Options
@@ -81,9 +84,25 @@ wrangler deploy
8184
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 [`ctx`](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:
8285

8386
```js
84-
// @errors: 7031
87+
// @filename: ambient.d.ts
88+
import { DurableObjectNamespace } from '@cloudflare/workers-types';
89+
90+
declare global {
91+
namespace App {
92+
interface Platform {
93+
env: {
94+
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
95+
};
96+
}
97+
}
98+
}
99+
// @filename: +server.js
100+
// ---cut---
101+
// @errors: 2355 2322
102+
/// file: +server.js
103+
/** @type {import('./$types').RequestHandler} */
85104
export async function POST({ request, platform }) {
86-
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
105+
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
87106
}
88107
```
89108

apps/svelte.dev/content/docs/kit/25-build-and-deploy/80-adapter-netlify.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1212
Install with `npm i -D @sveltejs/adapter-netlify`, then add the adapter to your `svelte.config.js`:
1313

1414
```js
15-
// @errors: 2307
1615
/// file: svelte.config.js
1716
import adapter from '@sveltejs/adapter-netlify';
1817

19-
export default {
18+
/** @type {import('@sveltejs/kit').Config} */
19+
const config = {
2020
kit: {
2121
// default options are shown
2222
adapter: adapter({
@@ -31,6 +31,8 @@ export default {
3131
})
3232
}
3333
};
34+
35+
export default config;
3436
```
3537

3638
Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-builds/file-based-configuration) file in the project root. This will determine where to write static assets based on the `build.publish` settings, as per this sample configuration:
@@ -52,11 +54,11 @@ New projects will use the current Node LTS version by default. However, if you'r
5254
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.
5355

5456
```js
55-
// @errors: 2307
5657
/// file: svelte.config.js
5758
import adapter from '@sveltejs/adapter-netlify';
5859

59-
export default {
60+
/** @type {import('@sveltejs/kit').Config} */
61+
const config = {
6062
kit: {
6163
adapter: adapter({
6264
// will create a Netlify Edge Function using Deno-based
@@ -65,6 +67,8 @@ export default {
6567
})
6668
}
6769
};
70+
71+
export default config;
6872
```
6973

7074
## Netlify alternatives to SvelteKit functionality
@@ -93,10 +97,15 @@ During compilation, redirect rules are automatically appended to your `_redirect
9397
With this adapter, SvelteKit endpoints are hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify function handlers have additional context, including [Netlify Identity](https://docs.netlify.com/visitor-access/identity/) information. You can access this context via the `event.platform.context` field inside your hooks and `+page.server` or `+layout.server` endpoints. These are [serverless functions](https://docs.netlify.com/functions/overview/) when the `edge` property is `false` in the adapter config or [edge functions](https://docs.netlify.com/edge-functions/overview/#app) when it is `true`.
9498

9599
```js
96-
// @errors: 2705 7006
100+
// @errors: 2339
101+
// @filename: ambient.d.ts
102+
/// <reference types="@sveltejs/adapter-netlify" />
103+
// @filename: +page.server.js
104+
// ---cut---
97105
/// file: +page.server.js
106+
/** @type {import('./$types').PageServerLoad} */
98107
export const load = async (event) => {
99-
const context = event.platform.context;
108+
const context = event.platform?.context;
100109
console.log(context); // shows up in your functions log in the Netlify app
101110
};
102111
```

apps/svelte.dev/content/docs/kit/25-build-and-deploy/90-adapter-vercel.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1212
Install with `npm i -D @sveltejs/adapter-vercel`, then add the adapter to your `svelte.config.js`:
1313

1414
```js
15-
// @errors: 2307 2345
1615
/// file: svelte.config.js
1716
import adapter from '@sveltejs/adapter-vercel';
1817

19-
export default {
18+
/** @type {import('@sveltejs/kit').Config} */
19+
const config = {
2020
kit: {
2121
adapter: adapter({
2222
// see below for options that can be set here
2323
})
2424
}
2525
};
26+
27+
export default config;
2628
```
2729

2830
## Deployment configuration
@@ -73,7 +75,8 @@ You may set the `images` config to control how Vercel builds your images. See th
7375
/// file: svelte.config.js
7476
import adapter from '@sveltejs/adapter-vercel';
7577

76-
export default {
78+
/** @type {import('@sveltejs/kit').Config} */
79+
const config = {
7780
kit: {
7881
adapter: adapter({
7982
images: {
@@ -85,6 +88,8 @@ export default {
8588
})
8689
}
8790
};
91+
92+
export default config;
8893
```
8994

9095
## Incremental Static Regeneration
@@ -96,9 +101,9 @@ Vercel supports [Incremental Static Regeneration](https://vercel.com/docs/increm
96101
To add ISR to a route, include the `isr` property in your `config` object:
97102

98103
```js
99-
// @errors: 2664
100104
import { BYPASS_TOKEN } from '$env/static/private';
101105

106+
/** @type {import('@sveltejs/adapter-vercel').Config} */
102107
export const config = {
103108
isr: {
104109
expiration: 60,
@@ -147,7 +152,6 @@ A list of valid query parameters that contribute to the cache key. Other paramet
147152
Vercel makes a set of [deployment-specific environment variables](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables) available. Like other environment variables, these are accessible from `$env/static/private` and `$env/dynamic/private` (sometimes — more on that later), and inaccessible from their public counterparts. To access one of these variables from the client:
148153

149154
```js
150-
// @errors: 2305
151155
/// file: +layout.server.js
152156
import { VERCEL_COMMIT_REF } from '$env/static/private';
153157

0 commit comments

Comments
 (0)