Deployment Guide
Learn how to deploy your VitePress documentation site to various platforms.
Building for Production
Build your site for production:
bash
npm run docs:buildThis generates static files in docs/.vitepress/dist/.
Deployment Platforms
GitHub Pages
- Create a
.github/workflows/deploy.ymlfile:
yaml
name: Deploy to GitHub Pages
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run docs:build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/.vitepress/dist- Configure the base URL in
site.config.js:
javascript
site: {
base: "/your-repo-name/",
}GitLab Pages
This template includes a .gitlab-ci.yml file for GitLab Pages deployment.
Update the base in site.config.js if needed:
javascript
site: {
base: "/your-project-name/",
}The CI/CD pipeline will automatically deploy on push to the main branch.
Netlify
- Connect your repository to Netlify
- Configure build settings:
- Build command:
npm run docs:build - Publish directory:
docs/.vitepress/dist
- Build command:
Vercel
- Import your repository to Vercel
- Configure build settings:
- Build command:
npm run docs:build - Output directory:
docs/.vitepress/dist
- Build command:
Custom Server
After building, upload the contents of docs/.vitepress/dist/ to your web server.
Configure your web server to:
- Serve
index.htmlfor directory requests - Handle 404s by serving the custom 404 page
- Enable gzip compression for better performance
Base URL Configuration
If deploying to a subdirectory, update the base in site.config.js:
javascript
site: {
base: "/subdirectory/",
}This ensures all links and assets work correctly.
Environment-Specific Configuration
You can use environment variables for different deployment environments:
javascript
export default {
site: {
base: process.env.BASE_URL || "/",
},
}Then set the environment variable during build:
bash
BASE_URL=/my-docs/ npm run docs:buildTroubleshooting
Links Not Working
- Ensure
baseis set correctly insite.config.js - Check that all internal links are relative or use the correct base path
Assets Not Loading
- Verify assets are in the
docs/public/directory - Check that asset paths in markdown are correct
- Ensure the build process includes all necessary files
404 Errors
- Configure your hosting platform to handle SPAs correctly
- Ensure the 404 page is properly configured in VitePress