Deploying Your VitePress Site
VitePress generates static HTML files that can be deployed to any hosting platform. This guide covers building for production and deploying to popular platforms.Prerequisites
These deployment guides assume:- VitePress site is in the
docsdirectory - Using default build output directory (
.vitepress/dist) - VitePress installed as a local dependency
- npm scripts configured in
package.json:
package.json
Build and Test Locally
1
Build your site
Generate static HTML for production:Built files are output to
.vitepress/dist.2
Preview locally
Test the production build before deploying:The preview server runs at
http://localhost:4173.3
Configure port (optional)
Change the preview server port:
package.json
Setting a Public Base Path
If your site is served from a subdirectory, set thebase option:
.vitepress/config.js
GitHub Pages example: Deploying to
user.github.io/repo/ requires base: '/repo/'HTTP Cache Headers
Optimize performance with proper cache headers for static assets.Understanding Asset Hashing
VitePress uses content-based hashing for assets:Recommended Cache Headers
For files in theassets/ directory:
- Netlify
- Vercel
- Nginx
Platform-Specific Guides
Netlify / Vercel / Cloudflare Pages / AWS Amplify / Render
These platforms work similarly - configure via dashboard:1
Connect repository
Link your Git repository to the platform.
2
Configure build settings
- Build Command:
npm run docs:build - Output Directory:
docs/.vitepress/dist - Node Version:
20(or above)
3
Deploy
Push to your main branch to trigger deployment.
GitHub Pages
Deploy automatically using GitHub Actions:1
Create workflow file
Create
.github/workflows/deploy.yml:.github/workflows/deploy.yml
2
Configure Pages source
In repository settings under Pages, set:
- Source: GitHub Actions
3
Set base path
Update
.vitepress/config.js:4
Deploy
Push to
main branch. Your site deploys to:https://username.github.io/repository/For pnpm or yarn, uncomment the relevant sections in the workflow file and update the cache and install commands.
GitLab Pages
Deploy using GitLab CI:1
Configure output directory
GitLab Pages requires output in
public/:.vitepress/config.js
2
Create CI configuration
Create
.gitlab-ci.yml in repository root:.gitlab-ci.yml
3
Deploy
Push to the
main branch to trigger the pipeline.Azure Static Web Apps
1
Follow Azure documentation
See the official Azure Static Web Apps guide.
2
Configure build settings
Set these values in your configuration:
app_location:/output_location:docs/.vitepress/distapp_build_command:npm run docs:build
Firebase
1
Create Firebase config
Create
firebase.json and .firebaserc in your repository root:firebase.json
.firebaserc
2
Build and deploy
Surge
Quick deployment with Surge:Custom Nginx Server
Example Nginx configuration with gzip compression and proper caching:This assumes your built site is in
/app. Adjust the root directive for your setup.Additional Platforms
CloudRay
Deploy with CloudRay - follow their VitePress guide
Hostinger
Deploy to Hostinger - see their deployment guide
Kinsta
Deploy to Kinsta - follow their VitePress example
Stormkit
Deploy to Stormkit - see their deployment guide
Build Options
Customize the build process with command-line options:Output Directory
Change the build output location:.vitepress/config.js
Base Path at Build Time
Override the base path during build:MPA Mode
Build as a traditional multi-page application (disables client-side routing):.vitepress/config.js
Troubleshooting
Build Fails on CI
Ensure Node.js version 18 or higher:404 on Deployment
Check your base path configuration matches your hosting setup:- Root domain:
base: '/'(default) - Subdirectory:
base: '/subdirectory/'
Assets Not Loading
Verify:- Base path includes trailing slash:
base: '/repo/'not'/repo' - Assets are in
docs/public/or imported in components - Cache headers are properly configured
Clean URLs Not Working
Enable clean URL support on your hosting platform or disable in config:.vitepress/config.js
Next Steps
Performance Optimization
Learn how to optimize your VitePress site for maximum performance
Custom Domain
Set up a custom domain for your deployed site
Analytics
Add analytics tracking to your VitePress site
SEO
Optimize your site for search engines