Have to do

Set the correct base in docs/.vuepress/config.js.

If you want to publish to https://

.github. IO /, you can skip this step because base defaults to “/”.

If you intend to publish to https://

.github. IO /

/ (that is, your repository is at https://github.com/

/

), set base to /

/.

Deliver solutions

Sh script

#! /usr/bin/env sh
Make sure the script throws the errors it encounters
set -e

# Generate static files
npm run docs:build

Enter the generated folder
cd docs/.vuepress/dist

# if publishing to a custom domain name
# echo 'www.example.com' > CNAME

git init
git add -A
git commit -m 'deploy'

# if published to https://
      
       .github. IO
      
# git push -f [email protected]:<USERNAME>/<USERNAME>.github.io.git master

# if published to https://
      
       .github. IO /
       
# git push -f [email protected]:<USERNAME>/<REPO>.git master:gh-pages

cd -
Copy the code

Travis CI

language: node_js
node_js:
  - lts/*
install:
  - yarn install # npm ci
script:
  - yarn docs:build # npm run docs:build
deploy:
  provider: pages
  skip_cleanup: true
  local_dir: docs/.vuepress/dist
  github_token: $GITHUB_TOKEN # Generated on GitHub to allow Travis to push code to your repository On Travis' project Settings page, set it to Secure Variable
  keep_history: true
  on:
    branch: master
Copy the code

Github Actions

Create a new deploy. Yml file under github/workflow/

name: Publish docs to github actions
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work  correctly.
        with:
          persist-credentials: false
      - name: Install
        run: npm ci && npm run-script docs:build
      - name: Install SSH Client
        uses: Webfactory/[email protected] # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace.
        with:
          ssh-private-key: The ${{ secrets.DEPLOY_KEY }}

      - name: Build and Deploy Repo
        uses: JamesIves/github-pages-deploy-action@releases/v3-test
        with:
          BASE_BRANCH: master
          BRANCH: gh-pages
          FOLDER: docs/.vuepress/dist
          SSH: true # SSH must be set to true so the deploy action knows which protocol to deploy with.
Copy the code

So let’s generate the key, first of all

ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
# You will get 2 files:
# gh-pages.pub (public key)
# gh-pages (private key)
Copy the code

Open the Settings of the repository, click Secrets and add the private key we just generated (gh-pages content) with name DEPLOY_KEY

Then click the Deploy Keys and add the public key (gh-pages. Pub content). Make sure to check Allow Write Access

Then submit, and it will automatically be published