VitePress 构建的博客如何部署到 github 平台?

VitePress 构建的博客如何部署到 github 平台?

1. 新建 github 项目

2. 构建 VitePress 项目

2.1. 设置 config 中的 base

由于我们的项目名称为 vite-press-demo,所以我们把 base 设置为 /vite-press-demo/,需注意前后 /

ts 复制代码
export default defineConfig({
  base: '/vite-press-demo/',
  ...,
})

2.2. 页面显示异常

这个时候你发现本地页面显示异常

是因为配置了 base 之后,导致路径不正确,点击上面的链接即可

2.3. favicon 显示异常

配置好 base 之后,你发现其他页面都没问题,图片也都能正常显示,但是 favicon 不能正常显示。

只需要把 head 中配置的 icon 路径改下即可,加上 /vite-press-demo 前缀

ts 复制代码
head: [
    ['link', { rel: 'icon', href: '/vite-press-demo/extension.ico'}],
], // 加上 /vite-press-demo 前缀

2.4. 运行 pnpm run docs:build 进行项目构建

项目正常构建成功

3. 项目发布到 github 上

3.1. clone 项目,并把构建的内容发布到 main 分支

是构建之后 dist 文件夹中的内容,不包括 dist 文件夹

shell 复制代码
.
├── 404.html
├── README.md
├── api
├── assets
├── basic
├── components
├── core
├── develop.svg
├── ext-2.svg
├── ext.svg
├── extension.ico
├── hashmap.json
├── index.html
├── react.svg
├── summarize
├── teach
├── team
├── tj.svg
└── vue.svg

3.2. 部署到 github

3.2.1. 点击 Setting 按钮
3.2.2. 点击 Pages 按钮
3.2.3. 找到 Branch,并下拉选择 main 分支
3.2.4. 点击 Save 保存
3.2.5. 等...

等几分钟,一般一分钟以内

不停的刷新当前页面也行

然后就会发现当前页面多了个 Visit site 模块

3.2.6. 点击 Visit site

点击之后,就跳转到对应的网站链接啦...

我这边是这个:https://18055975947.github.io/vite-press-demo/

4. 更新项目

当文档内容需要更新的时候,在开发完成之后,重新构建完成,把 dist 文件夹中内容重新发布到 main 分支即可,剩下的就是等就行

也可以点击 Setting-> Pages 模块刷新页面

可以看到这下面有部署的时间点

二、总结

1. 项目目录

shell 复制代码
.
├── docs
│   ├── .vitepress
│   │   ├── config.mts
│   │   └── utils.ts
│   ├── api
│   │   ├── api1.md
│   │   ├── api2.md
│   │   └── index.md
│   ├── basic
│   │   ├── basic1.md
│   │   ├── basic2.md
│   │   └── index.md
│   ├── components
│   │   └── test.md
│   ├── core
│   │   ├── core1.md
│   │   ├── core2.md
│   │   └── index.md
│   ├── index.md
│   ├── public
│   │   ├── basic
│   │   │   ├── basic-desc.png
│   │   │   └── basic-popup.png
│   │   ├── develop.svg
│   │   ├── ext-2.svg
│   │   ├── ext.svg
│   │   ├── extension.ico
│   │   ├── react.svg
│   │   ├── tj.svg
│   │   └── vue.svg
│   ├── summarize
│   │   ├── index.md
│   │   ├── summarize1.md
│   │   └── summarize2.md
│   ├── teach
│   │   ├── index.md
│   │   ├── teach1.md
│   │   └── teach2.md
│   └── team
│       ├── index.md
│       ├── team1.md
│       └── team2.md
├── package.json
└── pnpm-lock.yaml

2. 项目代码

源码:【develop 分支

Demo 预览:【demo 项目预览

使用 Vitepress 构建博客https://blog.csdn.net/guoqiankunmiss/article/details/138163772

相关推荐
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
linkcoco11 小时前
记录h5使用navigator.mediaDevices.getUserMedia录制音视频
前端·javascript·vue·音视频·js
Pro_er11 小时前
Vue3组件通信全攻略:多种方式详解+实战场景,轻松玩转复杂数据流!
vue·前端开发
放学-别走13 小时前
基于springboot 以及vue前后端分离架构的求职招聘系统设计与实现
java·mysql·spring·vue·毕业设计·springboot·毕设
oneouto13 小时前
项目实践 之 pdf简历的解析和填充(若依+vue3)
java·vue
程序视点1 天前
惊喜升级!Claude 3.7 Sonnet 上线 GitHub Copilot!已全账号开放!
github·claude·github copilot
今晚打老虎z1 天前
MailKit: 在 .NET 中实现高效电子邮件发送与接收
git·github·.net
奶凶的小熊崽1 天前
uView UI组件库http介绍和封装
uni-app·vue·uview
架构文摘JGWZ1 天前
5个GitHub热点开源项目!!
学习·github·工具
Pro_er2 天前
Vue3条件与列表渲染深度解析:实战技巧助你高效开发复杂界面
vue·前端开发