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/'
}

GitHub Pages

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:

Setting
Value

Build Command

npm run docs:build

Output Directory

docs/.vitepress/dist

Node Version

20 (or above)

Warning: Don't enable "Auto Minify" for HTML - it removes Vue hydration comments.

Vercel Configuration

For clean URLs, add vercel.json:

GitLab Pages

Create .gitlab-ci.yml:

Set outDir: '../public' in config if needed.

Firebase

Nginx

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

Other Platforms

Platform
Guide

Azure Static Web Apps

Set app_location: /, output_location: docs/.vitepress/dist

Surge

npx surge docs/.vitepress/dist

Heroku

Use heroku-buildpack-static

Render

Build: npm run docs:build, Publish: docs/.vitepress/dist

Key Points

  • 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

Last updated

Was this helpful?