Deploy Vite to the edge
A Vite app is built once and served as static files from Cloudflare's network. React, Vue, Svelte, Solid, Preact and plain Vite projects all deploy the same way.
Detection
A project is treated as Vite when vite is in dependencies or devDependencies, and either:
- its
buildscript runsvite build("build": "vite build", or"tsc && vite build"as in create-vite's TypeScript templates); - or a
vite.config.ts,.js,.mjsor.cjsfile sits at its root.
A project with vite but neither fails to build: no supported framework is found. Add an empty config to opt in:
Defaults
| Setting | Default |
|---|---|
| Install command | From your lockfile, see Frameworks |
| Build command | npx vite build |
| Output directory | dist |
If your config sets build.outDir, set the same output directory on the project.
Environment variables
Vite inlines import.meta.env.VITE_* values into your bundle at build time. Add them as build variables: in the dashboard, a new variable on a Vite project is a build variable by default.
Only VITE_-prefixed variables reach your code (unless you change Vite's envPrefix); the others are readable from vite.config.ts through process.env. Whatever ends up in the bundle is downloaded by every visitor, which is why a secret can't be a build variable.
For one deployment only, pass them to the CLI:
Client-side routing
Client-side routers (React Router, Vue Router, TanStack Router…) work as they are. A request for a path with no matching file, like opening or reloading /settings, gets your index.html, and the router takes it from there.
This holds as long as your output has no 404.html at its root. With one, unknown paths serve that page with a 404 status instead: right for a multi-page site, wrong for a single-page app. See Static sites.