Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

vite.config.ts

38 lines1.9 KB

1import { defineConfig } from 'vite'
2import { cloudflare } from '@cloudflare/vite-plugin'
3import { tanstackStart } from '@tanstack/react-start/plugin/vite'
4import viteReact from '@vitejs/plugin-react'
5import tailwindcss from '@tailwindcss/vite'
6​
7// TanStack Start on Cloudflare Workers: the Cloudflare Vite plugin runs the app
8// (and its Durable Objects + Container) inside `workerd` for both `vite dev` and
9// `wrangler deploy`, so the agent's `RunCoordinator`/`Sandbox` DOs and the
10// container behave the same locally as in production. The plugin reads bindings
11// + the custom `main` (`src/server.ts`) from `wrangler.jsonc`.
12//
13// NO tunnel needed for local agent runs — the bridge surface is reached without a
14// public hostname:
15// • Bridge (container → Worker `/_bridge`): `host.docker.internal:3001` — the
16// container reaches the host machine via the Docker host gateway.
17// Browser-facing PREVIEWS of the agent-built app do NOT go through this dev server:
18// `exposePreview` opens a Cloudflare quick tunnel (`*.trycloudflare.com`) served by
19// `cloudflared` inside the sandbox. That bypasses Vite's port entirely — previously
20// the preview was forced onto `*.localhost:3001` and Vite's dev middleware hijacked
21// its `/@vite/client` / `/src/*` / `/@fs/*` requests (serving them from the host,
22// not the container), which broke the page. See `PREVIEW_GUIDANCE` / `exposePreviewTool`.
23export default defineConfig({
24 server: {
25 // Bind ALL interfaces (not just 127.0.0.1) so the sandbox container can reach
26 // the dev server at `host.docker.internal:3001` for the `/_bridge` callback.
27 // Default loopback-only binding is why that call gets ECONNREFUSED.
28 host: true,
29 // Accept the bridge callback host.
30 allowedHosts: ['host.docker.internal'],
31 },
32 plugins: [
33 cloudflare({ viteEnvironment: { name: 'ssr' } }),
34 tailwindcss(),
35 tanstackStart(),
36 viteReact(),
37 ],
38})