# Deploying to Netlify

> Source: https://agilitycms.com/docs/sveltekit/deploying-to-netlify

Netlify is a first-class target for the [SvelteKit starter](https://github.com/agility/sveltekit-starter): `@sveltejs/adapter-auto` detects Netlify and uses the Netlify adapter automatically.

## 1. Push the repo

Push your copy of the starter to GitHub (or GitLab/Bitbucket).

## 2. Create the site

In the Netlify dashboard, **Add new site → Import an existing project**, pick the repo. Netlify detects SvelteKit; the defaults (`npm run build`) are correct.

## 3. Set the environment variables

Set these under *Site configuration → Environment variables* **before building** — the starter reads them from `$env/static/private`, which is inlined at build time:

| Variable | Value |
| --- | --- |
| `AGILITY_GUID` | Your instance GUID (*Settings → API Keys*) |
| `AGILITY_API_FETCH_KEY` | Fetch (live) API key |
| `AGILITY_API_PREVIEW_KEY` | Preview API key |
| `AGILITY_SITEMAP` | Sitemap/channel reference name (e.g. `website`) |
| `AGILITY_LOCALES` | Locale code (e.g. `en-us`) |

Trigger the first deploy — the sitemap prerenders at build time.

## 4. Rebuild when editors publish

Published changes appear after a rebuild (the starter prerenders — see [Routing & Sitemaps](/docs/sveltekit/routing-sitemaps)):

1. In Netlify: *Site configuration → Build & deploy → Build hooks* → add a hook and copy its URL.
2. In Agility: *Settings → Webhooks* → add a webhook on **publish** events pointing at the Build Hook URL.

## Optional: pin the adapter

```bash
npm i -D @sveltejs/adapter-netlify@6
```

> The starter uses SvelteKit 2. `@sveltejs/adapter-netlify` 7 and later require SvelteKit 3, so install version 6 until you upgrade the starter to SvelteKit 3.

```js
// svelte.config.js
import adapter from '@sveltejs/adapter-netlify';
export default { kit: { adapter: adapter() } };
```

> **Preview mode note:** the starter's preview toggle is for local dev. Production serves **published** content; review staged content locally with `npm run dev`, or stand up a second Netlify site built with the preview key.

---

Index of every docs page: https://agilitycms.com/docs/llms.txt
