项目部署
- GitHub Pages
- 在
docs/.vuepress/config.js
中设置正确的base
。
module.exports = {
base: '/blog/'
// 如果你打算发布到 https://<USERNAME>.github.io/,则可以省略这一步,因为 base 默认即是 "/"
// 如果你打算发布到 https://<USERNAME>.github.io/<REPO>/(也就是说你的仓库在 https://github.com/<USERNAME>/<REPO>),则将 base 设置为 "/<REPO>/"
}
1
2
3
4
5
2
3
4
5
- 在你的项目中,创建一个如下的
deploy.sh
(跟docs同级) 文件(请自行判断去掉高亮行的注释):
#!/usr/bin/env sh
# 确保脚本抛出遇到的错误
set -e
# 生成静态文件
npm run docs:build
# 进入生成的文件夹
cd docs/.vuepress/dist
# 如果是发布到自定义域名
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
# 如果发布到 https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
# 如果发布到 https://<USERNAME>.github.io/<REPO>
# git push -f git@github.com:muou2125/blog.git master:gh-pages
cd -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
- 在
package.json
的scripts
中新增代码
"scripts": {
"deploy": "bash deploy.sh"
}
1
2
3
2
3
- 在项目目录中右键选择
git bash here
,输入npm run deploy
,如果执行中没报任何错误,那等完成就行
...
...
Enumerating objects: 38, done.
Counting objects: 100% (38/38), done.
Delta compression using up to 12 threads
Compressing objects: 100% (35/35), done.
Writing objects: 100% (38/38), 122.11 KiB | 321.00 KiB/s, done.
Total 38 (delta 14), reused 0 (delta 0)
remote: Resolving deltas: 100% (14/14), done.
To github.com:muou2125/blog.git
+ cc29483...a9ec59c master -> gh-pages (forced update)
/e/vuePress
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- 我在执行
npm run deploy
后,报错
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
1
2
3
4
5
2
3
4
5
说明SSH keys没有设置或者过期了。根本原因还是权限问题,那么往下走解决问题
// 5.1 通过命令 cd ~/.ssh 切换到当前计算机当前用户的.ssh目录下
cd ~/.ssh
// 5.2 通过命令 ssh-keygen 生成 SSH key
ssh-keygen
// 5.3 根据命令 ssh-keygen 提示输入key要存储的位置以及密码(也可以什么都不输入,直接回车向下执行)
// 5.4 生成key后在指定要存储的地方找到id_rsa.pub(上一步执行完后有输出文件位置,如果实在找不到,那推荐神器everything,装好后,直接搜索.ssh即可)
// 5.5 在github的Settings中新建一个SSH key,将id_rsa.pub中的内容复制到Key中保存
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 附上Git用户名的查看和修改
// 查看用户名和邮箱地址
$ git config user.name
$ git config user.email
// 修改全局用户名和邮箱地址
$ git config --global user.name "username"
$ git config --global user.email "email"
// 修改局部用户名和邮箱地址
$ cd ~/your projectName
$ git config user.name "username"
$ git config user.email "email"
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12