deploy.cc自托管应用部署手册
deploy.cc / 框架指南 / Vite(React / Vue SPA)

Vite(React / Vue SPA) 部署指南

Vite 构建的单页应用(React / Vue / Svelte)输出静态文件到 dist/。关键是路由回退:所有未知路径都要返回 index.html。

构建命令
npm run build
输出目录
dist/
官方文档
Vite Deploying a Static Site · Cloudflare Pages SPA rendering

部署方式

  1. npm run build,上传 dist/。
  2. Nginx:location / { try_files $uri $uri/ /index.html; }(nginx.cc 生成器有 SPA 场景)。
  3. Netlify:在 public/_redirects 写 /* /index.html 200。
  4. Cloudflare Pages:项目里没有 404.html 时默认按 SPA 处理(见官方 Serving Pages 文档)。
  5. GitHub Pages:部署到子路径时设置 Vite 的 base;GitHub Pages 本身没有 SPA 回退,常见做法是复制 index.html 为 404.html(会返回 404 状态码)。

各平台说明

平台说明
Cloudflare Pages / Netlify / Vercel构建 npm run build,输出 dist。
VPS + Nginxtry_files 回退到 index.html。

注意事项

生成部署配置