使用vuepress-deploy自动部署vuepress静态网站至GitHub Pages

3mricR.png

vuepress是个静态网站(博客)生成器,具有非常好的加载性能和搜索引擎优化,如果你使用过vue的话,不妨试试,一定会让你爱不释手。

vuepress提供了几种部署方法,有本地脚本Travis CINetlify,但是不能完全满足我的需求。所以我开发了一个vuepress-deploy的自动化部署工具。可以去GitHub Action市场查看:https://github.com/marketplace/actions/vuepress-deploy

特性

  • 自动部署,可自由设置触发时机(如push完代码后)
  • 同时跑多个部署任务
  • 可以部署到本仓库、亦可部署到任何有权限的仓库
  • 支持自定义GitHub Pages域名,即支持自定义CNAME

在你项目仓库.github/workflows目录下创建一个 .yml文件,举例:vuepress-deploy.yml

name: Build and Deploy
on: [push]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@master

    - name: vuepress-deploy
      uses: jenkey2011/vuepress-deploy@master
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
        TARGET_REPO: username/repo
        TARGET_BRANCH: master
        BUILD_SCRIPT: yarn && yarn build
        BUILD_DIR: blog/.vuepress/dist/
        CNAME: https://www.dachangxiaoyuan.top

上述配置的结果是:每次推送代码,将自动构建、部署到username/repomaster分支。就是这么简单~

如果不了解 github workflow什么的,看下面的 详细教程

使用示例

仓库:

对应情况与部署文件设置:

  • A TO A:gh_pages: deploy-to-current-repo-gh_pages.yml
  • A TO B:master: deploy-to-other-repo-master.yml
  • A TO B:custom_branch: deploy-to-other-repo-custom_branch.yml

效果查看:

参数

参数 含义 类型 是否必须
ACCESS_TOKEN github的token secrets
TARGET_REPO 目标仓库,例: jenkey2011/blog默认当前仓库 env
TARGET_REPO 目标仓库的分支,例:gh-pages默认 gh-pages env
BUILD_SCRIPT 构建脚本 例: yarn && yarn build env
BUILD_DIR 构建产物的目录 e.g.: blog/.vuepress/dist/ env
CNAME Github Pages 站点别名 env no

详细教程

创建token

点击你的头像 > Settings > Developer settings > Personal access tokens > Generate new token.
权限至少要勾选repo,不清楚的,直接无脑全选就行~ 问题不大,不要慌。

详细信息看:https://help.github.com/en/github/authenticating-to-github/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on

创建secrets

你的vuepress项目源码仓库下 > Settings > Secrets, 创建ACCESS_TOKEN, 值就填写你刚才创建的token,确定。

创建一个任务文件

在项目根目录下,创建.github/workflows,然后再创建一个 .yml文件,名字随便取,例:vuepress-deploy.yml

详细信息看:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow

相关链接

【原文地址】使用vuepress-deploy自动部署vuepress静态网站至GitHub Pages

3mrM3d.png

你可能感兴趣的:(vuepress,前端,部署,github-pages,github-actions)