Vuepress 快速部署到 GitHub 即刻访问
环境
vuepress 版本 1.0.0
准备我们的 vuepress 网站
首先你应该先创建一个 Vuepress 项目
首先我们需要创建一个文件夹
![](https://img.haomeiwen.com/i15562516/34f7c4646bc9956d.png)
在文件夹内,打开 cmd 或 PowerShell
//会在文件夹内构建vuepress的整体结构
yarn create vuepress
![](https://img.haomeiwen.com/i15562516/0909dc38fe946810.png)
这里我们以docs为例
![](https://img.haomeiwen.com/i15562516/0bcd84c683598c88.png)
会让我们填一些信息,邮件、名字、描述什么的,这里我什么都不填
![](https://img.haomeiwen.com/i15562516/b8b6c818b6361d79.png)
执行
//安装所需依赖
yarn
然后我们去GitHub创建一个仓库
仓库名必须是你的GitHub名
仓库名必须是你的GitHub名
仓库名必须是你的GitHub名
仓库名必须以.github.io结尾
![](https://img.haomeiwen.com/i15562516/16c438cb9cb90bc6.png)
![](https://img.haomeiwen.com/i15562516/67aac6f7cab28ec2.png)
![](https://img.haomeiwen.com/i15562516/089ab7bd5f86c879.png)
回到vuepress来,在package.json中增加以下代码
"scripts": {
"docs:build": "vuepress build docs",//新增
"deploy": "bash deploy.sh"//新增
}
与package.json同级新建一个deploy.sh文件
在文件中写下面这段代码
#!/usr/bin/env sh
# 确保脚本抛出遇到的错误
set -e
# 生成静态文件
npm run docs:build
# 进入生成的文件夹
cd docs/.vuepress/dist
git init
git add -A
git commit -m 'deploy'
# 如果发布到 https://<USERNAME>.github.io 填写你刚刚创建的仓库地址
git push -f https://github.com/NicCraver/niccraver.github.io.git master
cd -
![](https://img.haomeiwen.com/i15562516/eb5cf5544f2bff48.png)
![](https://img.haomeiwen.com/i15562516/babe24840f0613a9.png)
最后我们通过gitbash执行
yarn deploy
![](https://img.haomeiwen.com/i15562516/698dec745c548cae.png)
![](https://img.haomeiwen.com/i15562516/669585f611293943.png)
打包后的文件会自动上传到GitHub上
打开https://niccraver.github.io/
项目就部署到GitHub上了
![](https://img.haomeiwen.com/i15562516/600d8b594f050d59.png)
网友评论