Files
test-repo/docs/DEPLOYMENT.md
T

96 lines
2.1 KiB
Markdown
Raw Normal View History

2026-05-20 10:43:18 +08:00
# Deployment Notes
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
## Base Path Auto-Adaptation
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
This project is a VitePress site that can be deployed to both **Vercel** and **GitHub Pages**. The main difference is the `base` path:
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
- Vercel: typically `/`
- GitHub Pages: typically `/easy-vibe/`
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
The VitePress config handles this automatically:
```js
2026-01-13 20:09:45 +08:00
// docs/.vitepress/config.mjs
const isVercel = process.env.VERCEL === '1'
const base = isVercel ? '/' : '/easy-vibe/'
```
2026-05-20 10:43:18 +08:00
## Environment Comparison
| Platform | Base | Example URL |
| --- | --- | --- |
| Vercel | `/` | `https://your-project.vercel.app/en/stage-1/...` |
| GitHub Pages | `/easy-vibe/` | `https://datawhalechina.github.io/easy-vibe/en/stage-1/...` |
| Local dev | `/easy-vibe/` | `http://localhost:5173/easy-vibe/en/stage-1/...` |
| Local preview | `/easy-vibe/` | `http://localhost:4173/easy-vibe/en/stage-1/...` |
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
## Home Redirect And Dynamic Links
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
The home page uses VitePress `withBase()` and `useData()` to avoid hardcoding the base path.
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
Example:
2026-01-13 20:09:45 +08:00
```vue
<script setup>
import { useData } from 'vitepress'
const { site } = useData()
const base = site.value.base
</script>
<template>
2026-05-20 10:43:18 +08:00
<a :href="base + 'en/stage-1/learning-map/'">Go</a>
2026-01-13 20:09:45 +08:00
</template>
```
2026-05-20 10:43:18 +08:00
## Deploy Steps
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
### Vercel
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
1. Push code to GitHub.
2. Import the repo in Vercel (or connect it).
3. Vercel will build automatically (see `vercel.json`).
2026-05-20 10:43:18 +08:00
Vercel usually sets `VERCEL=1` automatically.
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
### GitHub Pages
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
1. Configure GitHub Pages for the repo.
2. Build:
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
```bash
npm run build
```
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
3. Verify the published site: `https://datawhalechina.github.io/easy-vibe`
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
## Post-Deploy Checklist
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
- Home page loads.
- Navbar links navigate correctly.
- Locale switching works.
- Images load correctly.
2026-05-20 10:43:18 +08:00
## Troubleshooting
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
### Vercel URLs include `/easy-vibe/...` and return 404
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
Cause: `VERCEL` env var is missing or not equal to `1`.
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
Fix:
2026-05-20 10:43:18 +08:00
1. Check Vercel project settings -> Environment Variables.
2. Ensure `VERCEL=1`.
3. Redeploy.
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
### GitHub Pages returns 404 for all routes
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
Cause: missing `/easy-vibe/` base path in the build.
2026-01-13 20:09:45 +08:00
2026-05-20 10:43:18 +08:00
Fix:
2026-05-20 10:43:18 +08:00
1. Check `docs/.vitepress/config.mjs` base logic.
2. Ensure the GitHub Pages build uses `base = '/easy-vibe/'`.
3. Rebuild and redeploy.
2026-01-13 20:09:45 +08:00