Base
注意
base必须配置,否则打包会丢失css样式!!
根目录配置 /
,那么对应 https://xxx.github.io/
仓库 vitepress
配置 /vitepress/
,那么对应 https://xxx.github.io/vitepress
我们根据自己的需求,选择相应的的配置
js
export default defineConfig({
base: '/', //网站部署的路径,默认根目录
// base: '/vitepress/', //网站部署到github的vitepress这个仓库里
})
另一个要注意的点,部署到非根目录,Fav图标路径也要变动一下
js
export default defineConfig({
//fav图标
head: [
['link',{ rel: 'icon', href: '/logo.png'}], //部署到根目录
['link',{ rel: 'icon', href: '/vitepress/logo.png'}], //部署到vitepress仓库
],
})
部署
手动部署
构建完成后,在dist文件夹上传到Github即可
sh
npm run docs:build
默认的构建输出目录 .vitepress/dist
,将生成的所有文件上传到 Github 即可
上传成功后,在GitHub仓库 - 设置 - page里把分支改成main,默认root,保存
等创建成功后即可获得访问链接
自动部署1-脚本(推荐)
根目录下新建deploy.sh
sh
#!/usr/bin/env sh
# 确保脚本抛出遇到的错误
set -e
# 生成静态文件
# npm run docs:build
# npm run set NODE_OPTIONS=--openssl-legacy-provider && vuepress build .
# 进入生成的文件夹
cd docs/.vitepress/dist
#cd ./public
# 如果是发布到自定义域名
echo 'http://luckilyxxl.xyz' > CNAME
git init
git add -A
git commit -m 'deploy'
# 如果发布到 https://<USERNAME>.github.io
# git push -f [email protected]:<USERNAME>/<USERNAME>.github.io.git master
git push -f [email protected]:Daneliya/Daneliya.github.io.git master
#git push -f [email protected]:xu_xiaolong/xu_xiaolong.git master
# 如果发布到 https://<USERNAME>.github.io/<REPO>
# git push -f [email protected]:<USERNAME>/<REPO>.git master:gh-pages
cd -
执行构建docs:build
进入根目录下执行./deploy.sh
自动部署2-Vercel
Vercel :非常推荐,可以参考 Vercel注册到部署
自动部署3—Github Actions 工作流
在仓库 Actions
里新建一个工作流 中创建一个 deploy.yml
脚本文件
每次你更新代码后,系统会自动给你打包上传并部署
注意
名字可以自定义,不用非得用 deploy
,只要下面配置名和这个一致就行
分支默认是 main
yaml
# 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
#
name: Deploy VitePress site to Pages
on:
# 在针对 `main` 分支的推送上运行。如果你
# 使用 `master` 分支作为默认分支,请将其更改为 `master`
push:
branches: [main]
# 允许你从 Actions 选项卡手动运行此工作流程
workflow_dispatch:
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
concurrency:
group: pages
cancel-in-progress: false
jobs:
# 构建工作
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要
# - uses: pnpm/action-setup@v3 # 如果使用 pnpm,请取消此区域注释
# with:
# version: 9
# - uses: oven-sh/setup-bun@v1 # 如果使用 Bun,请取消注释
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm # 或 pnpm / yarn
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: npm ci # 或 pnpm install / yarn install / bun install
- name: Build with VitePress
run: npm run docs:build # 或 pnpm docs:build / yarn docs:build / bun run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# 部署工作
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
报错
(!) Found dead link ./index in file
解决:https://blog.csdn.net/sinat_31213021/article/details/143791615