React hosting guide

Vite React hosting

Most Vite React apps deploy as static assets. The important decisions are build output, client-side routing fallback, caching, and environment variable exposure.

Recommended starting point: Cloudflare Workers Static Assets

What matters most

The default Vite build outputs to dist. A static host can serve that directory directly when the app does not need server-side code.

If the app uses client-side routes, configure fallback behavior deliberately. Content sites usually need real 404s, while app dashboards may need SPA fallback.

Only variables prefixed for the browser should be included in client bundles. Treat every public environment variable as visible to users.

Deployment steps

  1. Run pnpm build and confirm dist contains index.html and hashed assets.
  2. Decide whether route misses should return index.html or a real 404 page.
  3. Add cache headers for immutable hashed assets and revalidated HTML.
  4. Deploy dist to a static-capable host and test direct visits to nested routes.

Related React hosting guides