-.- -.-
首页
  • 分类
  • 标签
  • 归档
  • Lodash 源码分析 (opens new window)
Mozilla (opens new window)
GitHub (opens new window)

江月何年初照人

首页
  • 分类
  • 标签
  • 归档
  • Lodash 源码分析 (opens new window)
Mozilla (opens new window)
GitHub (opens new window)
  • actions

  • pages

    • 部署 Github 静态页面
      • Vuepress
  • git
  • pages
江月何年初照人
2021-03-22

部署 Github 静态页面

# 部署 Github 静态页面

Github 提供了 GitHub Pages, 您可以为自己、您的组织或项目设置一个基本 GitHub Pages 站点

针对于 Vuepress , 我们也可以使用 GitHub Pages 来部署静态站点,达到在线访问的效果

关于 GitHub Pages 可查看官方文档 (opens new window)

# Vuepress

我们来看一下在 Vuepress 中,怎么将自己写的文档,发布到线上访问

  1. 在 docs/.vuepress/config.js 中设置正确的 base。

    如果你打算发布到 https://<USERNAME>.github.io/,则可以省略这一步,因为 base 默认即是 "/"。

    如果你打算发布到 https://<USERNAME>.github.io/<REPO>/,则将 base 设置为 /<REPO>/。

  2. 在你的项目中,创建一个如下的 deploy.sh 文件

#!/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:<USERNAME>/<REPO>.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
  1. 在 package.json 中添加 deploy 命令
  "scripts": {
    "deploy": "sh deploy.sh",
  }
1
2
3
  1. 在本地执行 deploy 命令即可发布到的 GitHub Pages

此时,打开项目的 Github,会发现多了分支

通过 https://<USERNAME>.github.io/<REPO>/ 即可进行访问

编辑 (opens new window)
#git
上次更新: 2021/03/24 18:42:24
使用 GitHub Actions 自动部署博客

← 使用 GitHub Actions 自动部署博客

最近更新
01
a标签下载限制
08-08
02
必应每日一图
05-27
03
小球碰壁反弹动画
05-26
更多文章>
Theme by Vdoing | Copyright © 2021-2023 Himawari | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式