@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
mdx 175 lines 4.95 KB
Raw
1 ---
2 title: TanStack Start
3 description: Deploy TanStack Start to Prisma Compute with Prisma.Website.TanStackStart — React or Solid SSR on Bun, with native Vite dev locally.
4 sidebar:
5 order: 8
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft";
11
12 `Prisma.Website.TanStackStart` builds [TanStack Start](https://tanstack.com/start)
13 for React or Solid through your project's Vite pipeline. The shared
14 Node target wraps its fetch handler as an HTTP server; SSR and client
15 assets run on **Bun in Prisma Compute** from a `tar.gz` upload. There
16 is no Docker image or registry.
17
18 ## Install
19
20 Install the build-time integration; the resource loads `/tanstack-start`
21 and `/tanstack-start/node` from your project:
22
23 <PackageManagers dev={devDeps} />
24
25 ## Configure Vite
26
27 Keep the framework plugin and normal Vite plugins. For React:
28
29 ```typescript
30 // vite.config.ts
31 import tailwindcss from "@tailwindcss/vite";
32 import { tanstackStart } from "@tanstack/react-start/plugin/vite";
33 import viteReact from "@vitejs/plugin-react";
34 import { defineConfig } from "vite";
35
36 export default defineConfig({
37 plugins: [tailwindcss(), tanstackStart(), viteReact()],
38 });
39 ```
40
41 The integration drives `builder.buildApp()` and makes the SSR bundle
42 self-contained. No deployment adapter is required.
43
44 :::caution[Remove the Cloudflare Vite plugin]
45 If the scaffold includes `@cloudflare/vite-plugin`, remove it. It
46 builds for workerd, not the Node-compatible target hosted on Prisma:
47
48 ```diff lang="typescript"
49 -import { cloudflare } from "@cloudflare/vite-plugin";
50 import { tanstackStart } from "@tanstack/react-start/plugin/vite";
51 import viteReact from "@vitejs/plugin-react";
52 import { defineConfig } from "vite";
53
54 export default defineConfig({
55 - plugins: [cloudflare({ viteEnvironment: { name: "ssr" } }), tanstackStart(), viteReact()],
56 + plugins: [tanstackStart(), viteReact()],
57 });
58 ```
59
60 :::
61
62 ## Declare the Website
63
64 ```typescript
65 // alchemy.run.ts
66 import * as Prisma from "@alchemy.run/prisma";
67
68 export const Website = Prisma.Website.TanStackStart("Website", {
69 rootDir: "./app",
70 });
71 ```
72
73 Omit `rootDir` for an app at `.`. Live deploy creates a database-less
74 Prisma project if `project` is omitted; pass an existing project to
75 share it with other apps.
76
77 ## Add it to the Stack
78
79 ```typescript
80 // alchemy.run.ts
81 import * as Alchemy from "alchemy";
82 import * as Effect from "effect/Effect";
83
84 export default Alchemy.Stack(
85 "MyTanStackSite",
86 { providers: Prisma.providers(), state: Alchemy.localState() },
87 Effect.gen(function* () {
88 const site = yield* Website;
89 return { url: site.url };
90 }),
91 );
92 ```
93
94 Client assets are served first; misses go to SSR, server routes, or
95 server functions. `site.url` is the Compute endpoint on deploy.
96
97 ## Add environment variables
98
99 ```diff lang="typescript"
100 export const Website = Prisma.Website.TanStackStart("Website", {
101 rootDir: "./app",
102 + env: { API_BASE: "https://api.example.com" },
103 });
104 ```
105
106 `env` is applied before build and dev and passed to Compute. Vite
107 inlines `VITE_*` values into the browser bundle; keep secrets out of
108 those keys. Sibling outputs can feed `env` inside the Stack generator.
109
110 ## Read the environment in a server function
111
112 ```typescript
113 // src/routes/index.tsx
114 import { createServerFn } from "@tanstack/react-start";
115
116 const getApiBase = createServerFn({ method: "GET" }).handler(() => ({
117 apiBase: process.env.API_BASE ?? "unset",
118 }));
119 ```
120
121 Server functions run on Bun and read `process.env`.
122
123 ## Read the environment in a server route
124
125 ```typescript
126 // src/routes/api.hello.ts
127 import { createFileRoute } from "@tanstack/react-router";
128
129 export const Route = createFileRoute("/api/hello")({
130 server: {
131 handlers: {
132 GET: () => new Response(process.env.API_BASE ?? "unset"),
133 },
134 },
135 });
136 ```
137
138 Server routes use the same process environment.
139
140 ## Build configuration
141
142 Your `vite.config.ts` is the build configuration. Keep Vite's default
143 output directory, `dist`; the integration reads `dist/server` and
144 `dist/client`. Static files are served by Compute, not deployed as an
145 independent CDN site.
146
147 ## Local dev
148
149 `bun alchemy dev` starts TanStack Start's native Vite server with HMR
150 and creates no Prisma resources for the Website. Opt into live deployment
151 during dev explicitly:
152
153 ```typescript
154 export const Website = Prisma.Website.TanStackStart("Website").pipe(
155 Alchemy.remote(),
156 );
157 ```
158
159 ## Custom domain
160
161 ```typescript
162 const site = yield* Prisma.Website.TanStackStart("Web", {
163 domain: "app.example.com",
164 });
165 ```
166
167 `Prisma.CustomDomain` requires the app to be on the current default
168 branch. Configure returned DNS records yourself and verify status before
169 cutover; see [Custom domains](/prisma/frontend/websites#custom-domains).
170
171 ## Where next
172
173 - [TanStack Start API](/providers/prisma/website/tanstackstart).
174 - [TanStack Start example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-tanstack-start).
175 - [Websites](/prisma/frontend/websites) and [Compute apps](/prisma/compute/apps).