Frequently Asked Questions
Basic Questions
Q: How do I start the development server?
A: Run the following command in the project root directory:
bash
npm run docs:devThe server will start at http://localhost:5173.
Q: How do I add a new page?
A: Follow these steps:
- Create a new
.mdfile in thedocs/en/directory - Add navigation configuration in
docs/.vitepress/config.mts - Restart the development server
Q: How do I modify the site title?
A: Modify the title configuration in docs/.vitepress/config.mts:
typescript
export default {
title: 'Your Site Title',
// ... other configurations
}Configuration Questions
Q: How do I add custom CSS?
A: Create a custom.css file in the docs/.vitepress/ directory, then import it in the configuration:
typescript
export default {
head: [
['link', { rel: 'stylesheet', href: '/custom.css' }]
]
}Q: How do I configure search functionality?
A: VitePress supports search by default. For more advanced search, you can configure Algolia DocSearch:
typescript
export default {
themeConfig: {
search: {
provider: 'algolia',
options: {
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
indexName: 'YOUR_INDEX_NAME'
}
}
}
}Q: How do I add Google Analytics?
A: Add the following to your configuration:
typescript
export default {
head: [
['script', { async: true, src: 'https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID' }],
['script', {}, `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'GA_MEASUREMENT_ID');`]
]
}Deployment Questions
Q: How do I deploy to GitHub Pages?
A: Follow these steps:
- Build the project:
npm run docs:build - Push the contents of
docs/.vitepress/distdirectory to GitHub - Enable GitHub Pages in repository settings
Q: How do I deploy to Netlify?
A: Follow these steps:
- Push your code to GitHub
- Connect your GitHub repository in Netlify
- Set build command:
npm run docs:build - Set publish directory:
docs/.vitepress/dist
Q: Pages show 404 after deployment?
A: This is usually due to routing configuration issues. Make sure:
- The
basepath is correctly configured indocs/.vitepress/config.mts - If deploying to a subdirectory, set
base: '/your-repo-name/'
Performance Questions
Q: How do I optimize build speed?
A: You can try the following methods:
- Use a faster package manager (like pnpm)
- Reduce unnecessary dependencies
- Use caching (like GitHub Actions cache)
Q: How do I reduce bundle size?
A: You can try the following methods:
- Use tree-shaking to remove unused code
- Compress images and static assets
- Use CDN to load third-party libraries
Troubleshooting
Q: Development server fails to start?
A: Check the following:
- Ensure Node.js version >= 16
- Delete
node_modulesandpackage-lock.json, reinstall dependencies - Check if the port is occupied
Q: Build fails?
A: Check the following:
- Ensure all Markdown files have correct syntax
- Check configuration file syntax
- Look at specific error messages in build logs
Q: Page styles are abnormal?
A: Check the following:
- Ensure CSS file paths are correct
- Check browser console for errors
- Clear browser cache
More Help
If the above questions don't solve your problem, you can:
- Check the VitePress official documentation
- Search for similar issues in GitHub Issues
- Join VitePress community discussions
