Deployment
Deploying VitePress sites to various platforms including GitHub Pages, Netlify, Vercel, and more
Deploy VitePress static sites to various hosting platforms.
Build and Preview
# Build production files
npm run docs:build
# Preview locally
npm run docs:preview
Output is in .vitepress/dist by default.
Setting Base Path
For sub-path deployment (e.g., https://user.github.io/repo/):
// .vitepress/config.ts
export default {
base: '/repo/'
}
Create .github/workflows/deploy.yml:
Enable GitHub Pages in repository settings → Pages → Source: "GitHub Actions".
For pnpm, add before setup-node:
Netlify / Vercel / Cloudflare Pages
Configure in dashboard:
Warning: Don't enable "Auto Minify" for HTML - it removes Vue hydration comments.
Vercel Configuration
For clean URLs, add vercel.json:
Create .gitlab-ci.yml:
Set outDir: '../public' in config if needed.
Important: Don't default to index.html like SPAs - use $uri.html for clean URLs.
HTTP Cache Headers
For hashed assets (immutable):
Netlify _headers
Place in docs/public/_headers:
Vercel vercel.json
Set app_location: /, output_location: docs/.vitepress/dist
npx surge docs/.vitepress/dist
Use heroku-buildpack-static
Build: npm run docs:build, Publish: docs/.vitepress/dist
Set base for sub-path deployments
GitHub Pages requires workflow file and enabling Pages in settings
Most platforms: Build npm run docs:build, output docs/.vitepress/dist
Don't enable HTML minification (breaks hydration)
Cache /assets/* with immutable headers
For clean URLs on Nginx, use try_files $uri $uri.html $uri/ =404