-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: move adapter docs to site (#8531)
* docs: more build docs Transforming the adapters document into a more general build doc closes #8500 * fix * docs: move adapter docs to site * update page titles * ignore typescript errors * revert url change * some more reversions * reorder sidebar * tweaks * rename to build and deploy * fix casing * tweaks * separate out writing section * tweaks * formatting * tweaks * expose App.Platform automatically if adapter-cloudflare-workers is installed * Update .changeset/hungry-singers-tease.md * Update .changeset/hungry-singers-tease.md * fix links * amend App.Platform * fix, hopefully * tweaks Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Rich Harris <hello@rich-harris.dev> Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
- Loading branch information
1 parent
c78008c
commit 1972a8f
Showing
28 changed files
with
975 additions
and
872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
--- | ||
|
||
feat: expose `App.Platform` interface automatically |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@sveltejs/adapter-auto': patch | ||
'@sveltejs/adapter-cloudflare': patch | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
'@sveltejs/adapter-netlify': patch | ||
'@sveltejs/adapter-node': patch | ||
'@sveltejs/adapter-static': patch | ||
'@sveltejs/adapter-vercel': patch | ||
--- | ||
|
||
docs: move adapter docs to site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-cloudflare-workers': patch | ||
--- | ||
|
||
fix: amend `App.Platform` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
documentation/docs/25-build-and-deploy/10-building-your-app.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: Building your app | ||
--- | ||
|
||
Building a SvelteKit app happens in two stages, which both happen when you run `vite build` (usually via `npm run build`). | ||
|
||
Firstly, Vite creates an optimized production build of your server code, your browser code, and your service worker (if you have one). [Prerendering](/docs/page-options#prerender) is executed at this stage, if appropriate. | ||
|
||
Secondly, an _adapter_ takes this production build and tunes it for your target environment — more on this on the following pages. | ||
|
||
## During the build | ||
|
||
SvelteKit will load your `+page/layout(.server).js` files (and all files they import) for analysis during the build. Any code that should _not_ be executed at this stage must check that `building` from [`$app/environment`](/docs/modules#$app-environment) is `false`: | ||
|
||
```diff | ||
+import { building } from '$app/environment'; | ||
import { setupMyDatabase } from '$lib/server/database'; | ||
|
||
+if (!building) { | ||
setupMyDatabase(); | ||
+} | ||
|
||
export function load() { | ||
// ... | ||
} | ||
``` | ||
|
||
## Preview your app | ||
|
||
After building, you can view your production build locally with `vite preview` (via `npm run preview`). Note that this will run the app in Node, and so is not a perfect reproduction of your deployed app — adapter-specific adjustments like the [`platform` object](adapters#platform-specific-context) do not apply to previews. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: Adapters | ||
--- | ||
|
||
Before you can deploy your SvelteKit app, you need to _adapt_ it for your deployment target. Adapters are small plugins that take the built app as input and generate output for deployment. | ||
|
||
Official adapters exist for a variety of platforms — these are documented on the following pages: | ||
|
||
- [`@sveltejs/adapter-cloudflare`](adapter-cloudflare) for Cloudflare Pages | ||
- [`@sveltejs/adapter-cloudflare-workers`](adapter-cloudflare-workers) for Cloudflare Workers | ||
- [`@sveltejs/adapter-netlify`](adapter-netlify) for Netlify | ||
- [`@sveltejs/adapter-node`](adapter-node) for Node servers | ||
- [`@sveltejs/adapter-static`](adapter-static) for static site generation (SSG) | ||
- [`@sveltejs/adapter-vercel`](adapter-vercel) for Vercel | ||
|
||
Additional [community-provided adapters](https://sveltesociety.dev/components#adapters) exist for other platforms. | ||
|
||
## Using adapters | ||
|
||
Your adapter is specified in `svelte.config.js`: | ||
|
||
```js | ||
/// file: svelte.config.js | ||
// @filename: ambient.d.ts | ||
declare module 'svelte-adapter-foo' { | ||
const adapter: (opts: any) => import('@sveltejs/kit').Adapter; | ||
export default adapter; | ||
} | ||
|
||
// @filename: index.js | ||
// ---cut--- | ||
import adapter from 'svelte-adapter-foo'; | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
kit: { | ||
adapter: adapter({ | ||
// adapter options go here | ||
}) | ||
} | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
## Platform-specific context | ||
|
||
Some adapters may have access to additional information about the request. For example, Cloudflare Workers can access an `env` object containing KV namespaces etc. This can be passed to the `RequestEvent` used in [hooks](/docs/hooks) and [server routes](/docs/routing#server) as the `platform` property — consult each adapter's documentation to learn more. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Zero-config deployments | ||
--- | ||
|
||
When you create a new SvelteKit project with `npm create svelte@latest`, it installs [`adapter-auto`](/~https://github.com/sveltejs/kit/tree/master/packages/adapter-auto) by default. This adapter automatically installs and uses the correct adapter for supported environments when you deploy: | ||
|
||
- [`@sveltejs/adapter-cloudflare`](adapter-cloudflare) for [Cloudflare Pages](https://developers.cloudflare.com/pages/) | ||
- [`@sveltejs/adapter-netlify`](adapter-netlify) for [Netlify](https://netlify.com/) | ||
- [`@sveltejs/adapter-vercel`](adapter-vercel) for [Vercel](https://vercel.com/) | ||
- [`svelte-adapter-azure-swa`](/~https://github.com/geoffrich/svelte-adapter-azure-swa) for [Azure Static Web Apps](https://docs.microsoft.com/en-us/azure/static-web-apps/) | ||
|
||
It's recommended to install the appropriate adapter to your `devDependencies` once you've settled on a target environment, since this will add the adapter to your lockfile and slightly improve install times on CI. | ||
|
||
## Environment-specific configuration | ||
|
||
To add configuration options, such as `{ edge: true }` in [`adapter-vercel`](adapter-vercel) and [`adapter-netlify`](adapter-netlify), you must install the underlying adapter — `adapter-auto` does not take any options. | ||
|
||
## Adding community adapters | ||
|
||
You can add zero-config support for additional adapters by editing [adapters.js](/~https://github.com/sveltejs/kit/blob/master/packages/adapter-auto/adapters.js) and opening a pull request. |
Oops, something went wrong.