TanStack Start 在 Cloudflare 上的重点不是“能部署”,而是 server functions 能直接进入 Workers 生态:bindings、D1、R2、KV、Queues、Workflows。
npm create cloudflare@latest -- my-tanstack-start-app --framework=tanstack-start
npm run dev
npm run deploy已有项目则安装 Cloudflare Vite plugin 和 Wrangler,并把 Vite 的 SSR environment 接到 Workers runtime。
npm i -D @cloudflare/vite-plugin wrangler// vite.config.ts
import { defineConfig } from 'vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { cloudflare } from '@cloudflare/vite-plugin'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [
cloudflare({ viteEnvironment: { name: 'ssr' } }),
tanstackStart(),
react(),
],
})// wrangler.jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-tanstack-start-app",
"compatibility_date": "2026-07-07",
"compatibility_flags": ["nodejs_compat"],
"main": "@tanstack/react-start/server-entry",
"observability": { "enabled": true }
}Cloudflare 文档显示,TanStack Start server-side code 可以通过 cloudflare:workers 的 env 访问 bindings。
import { createServerFn } from '@tanstack/react-start'
import { env } from 'cloudflare:workers'
const getProfile = createServerFn().handler(async () => {
const row = await env.DB.prepare('select * from profiles where id = ?')
.bind('me')
.first()
return row
})| 需求 | TanStack 部分 | Cloudflare 部分 |
|---|---|---|
| 公开内容页 | Start prerender/SSR | Static assets + CDN cache |
| 用户 dashboard | Router + Query + server functions | Workers + D1/KV |
| 文件上传 | server function mutation | R2 binding |
| 后台任务 | custom server entry | Queues / Cron / Workflows |
| AI 功能 | server function boundary | Workers AI / AI Gateway |
在 Cloudflare Workers 上访问 D1/R2/KV 的关键机制是什么?