The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | --- |
| 2 | title: SvelteKit |
| 3 | description: Deploy SvelteKit to Prisma Compute with Prisma.Website.SvelteKit — SSR and prerendered assets on Bun, with native Vite dev locally. |
| 4 | sidebar: |
| 5 | order: 12 |
| 6 | --- |
| 7 | |
| 8 | import PackageManagers from "../../../../components/PackageManagers.astro"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft"; |
| 11 | |
| 12 | `Prisma.Website.SvelteKit` builds [SvelteKit](https://svelte.dev/docs/kit) |
| 13 | with its Vite pipeline and an injected Node-target adapter. Client |
| 14 | assets, prerendered pages, and the server handler are uploaded as a |
| 15 | `tar.gz` artifact and served on **Bun in Prisma Compute**, not a Node |
| 16 | container. |
| 17 | |
| 18 | ## Install |
| 19 | |
| 20 | Install the build-time integration; the resource loads its `/sveltekit` |
| 21 | and `/sveltekit/node` exports from your project: |
| 22 | |
| 23 | <PackageManagers dev={devDeps} /> |
| 24 | |
| 25 | ## Configure SvelteKit |
| 26 | |
| 27 | This integration follows Kit v3: Kit options live in the |
| 28 | `sveltekit(...)` call in `vite.config.ts`, not `svelte.config.js`. |
| 29 | Your config loads natively. Alchemy injects its adapter; don't set |
| 30 | `kit.adapter`. An adapter declared in the native config is replaced |
| 31 | with a warning. |
| 32 | |
| 33 | ## Declare the Website |
| 34 | |
| 35 | ```typescript |
| 36 | // alchemy.run.ts |
| 37 | import * as Prisma from "@alchemy.run/prisma"; |
| 38 | |
| 39 | export const Website = Prisma.Website.SvelteKit("Website"); |
| 40 | ``` |
| 41 | |
| 42 | Use `rootDir` for an app outside `.`. Omit `project` to create a |
| 43 | database-less Prisma project on live deploy, or pass an existing project. |
| 44 | |
| 45 | ## Add it to the Stack |
| 46 | |
| 47 | ```typescript |
| 48 | // alchemy.run.ts |
| 49 | import * as Alchemy from "alchemy"; |
| 50 | import * as Effect from "effect/Effect"; |
| 51 | |
| 52 | export default Alchemy.Stack( |
| 53 | "MySvelteKitSite", |
| 54 | { providers: Prisma.providers(), state: Alchemy.localState() }, |
| 55 | Effect.gen(function* () { |
| 56 | const site = yield* Website; |
| 57 | return { url: site.url }; |
| 58 | }), |
| 59 | ); |
| 60 | ``` |
| 61 | |
| 62 | Routes with `export const prerender = true` are generated at build |
| 63 | time and served as files. Server routes and load functions run in the |
| 64 | Kit handler on Compute. `site.url` is the deployed endpoint. |
| 65 | |
| 66 | ## Add environment variables |
| 67 | |
| 68 | ```diff lang="typescript" |
| 69 | export const Website = Prisma.Website.SvelteKit("Website", { |
| 70 | + env: { |
| 71 | + GREETING: "Hello from Alchemy!", |
| 72 | + API_BASE: "https://api.example.com", |
| 73 | + }, |
| 74 | }); |
| 75 | ``` |
| 76 | |
| 77 | Values are applied before build and dev, and passed to Compute. These |
| 78 | are process environment variables, not Worker bindings. |
| 79 | |
| 80 | ## Read the environment in server code |
| 81 | |
| 82 | ```typescript |
| 83 | // src/routes/+page.server.ts |
| 84 | export const load = () => ({ |
| 85 | greeting: process.env.GREETING ?? "hello", |
| 86 | }); |
| 87 | ``` |
| 88 | |
| 89 | The Bun process exposes `process.env`; Kit's `$env/dynamic/private` |
| 90 | reads the server environment too. Keep secrets out of public env keys. |
| 91 | |
| 92 | ## Kit options |
| 93 | |
| 94 | Keep Vite plugins and ordinary Kit config in your app: |
| 95 | |
| 96 | ```typescript |
| 97 | // vite.config.ts |
| 98 | import { sveltekit } from "@sveltejs/kit/vite"; |
| 99 | import tailwindcss from "@tailwindcss/vite"; |
| 100 | import { defineConfig } from "vite"; |
| 101 | |
| 102 | export default defineConfig({ |
| 103 | plugins: [tailwindcss(), sveltekit({ prerender: { handleHttpError: "warn" } })], |
| 104 | }); |
| 105 | ``` |
| 106 | |
| 107 | The serializable `kit` bag overrides those options: |
| 108 | |
| 109 | ```typescript |
| 110 | export const Website = Prisma.Website.SvelteKit("Website", { |
| 111 | kit: { paths: { base: "/docs" } }, |
| 112 | }); |
| 113 | ``` |
| 114 | |
| 115 | Alchemy owns the adapter in both cases. |
| 116 | |
| 117 | ## Local dev |
| 118 | |
| 119 | `bun alchemy dev` starts SvelteKit's own Vite server with HMR. |
| 120 | `site.url` is local, and the Website creates no Prisma resources. |
| 121 | `.pipe(Alchemy.remote())` opts into live deployment during dev. |
| 122 | |
| 123 | ## Custom domain |
| 124 | |
| 125 | ```typescript |
| 126 | const site = yield* Prisma.Website.SvelteKit("Web", { |
| 127 | domain: "app.example.com", |
| 128 | }); |
| 129 | ``` |
| 130 | |
| 131 | This creates `Prisma.CustomDomain`. Configure its returned DNS records yourself |
| 132 | and check status before cutover. See |
| 133 | [Custom domains](/prisma/frontend/websites#custom-domains). |
| 134 | |
| 135 | ## Where next |
| 136 | |
| 137 | - [SvelteKit API](/providers/prisma/website/sveltekit). |
| 138 | - [SvelteKit example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-sveltekit). |
| 139 | - [Websites](/prisma/frontend/websites) and [Compute apps](/prisma/compute/apps). |