部署
下述的指南基于以下条件:
- Markdown 源文件放置在你项目的
docs目录; - 使用的是默认的构建输出目录 (
.vuepress/dist) ; - 使用 Yarn classic 作为包管理器,当然也可以使用 NPM 。
- VuePress 作为项目依赖安装,并在
package.json中配置了如下脚本:
{"scripts": {"docs:build": "vuepress build docs"}}
GitHub Pages
设置正确的 base 选项。
如果你准备发布到
https://<USERNAME>.github.io/,你可以省略这一步,因为base默认就是"/"。如果你准备发布到
https://<USERNAME>.github.io/<REPO>/,也就是说你的仓库地址是https://github.com/<USERNAME>/<REPO>,则将base设置为"/<REPO>/"。选择你想要使用的 CI 工具。这里我们以 GitHub Actions 为例。
创建
.github/workflows/docs.yml文件来配置工作流。
::: details 点击展开配置样例
name: docson:# 每当 push 到 main 分支时触发部署push:branches: [main]# 手动触发部署workflow_dispatch:jobs:docs:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2with:# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录fetch-depth: 0- name: Setup Node.jsuses: actions/setup-node@v1with:# 选择要使用的 node 版本node-version: '14'# 缓存 node_modules- name: Cache dependenciesuses: actions/cache@v2id: yarn-cachewith:path: |**/node_moduleskey: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}restore-keys: |${{ runner.os }}-yarn-# 如果缓存没有命中,安装依赖- name: Install dependenciesif: steps.yarn-cache.outputs.cache-hit != 'true'run: yarn --frozen-lockfile# 运行构建脚本- name: Build VuePress siterun: yarn docs:build# 查看 workflow 的文档来获取更多信息# @see https://github.com/crazy-max/ghaction-github-pages- name: Deploy to GitHub Pagesuses: crazy-max/ghaction-github-pages@v2with:# 部署到 gh-pages 分支target_branch: gh-pages# 部署目录为 VuePress 的默认输出目录build_dir: docs/.vuepress/distenv:# @see https://docs.github.com/cn/actions/reference/authentication-in-a-workflow#about-the-github_token-secretGITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
:::
::: tip 请参考 GitHub Pages 官方指南 来获取更多信息。 :::
GitLab Pages
设置正确的 base 选项。
如果你准备发布到
https://<USERNAME>.gitlab.io/,你可以省略这一步,因此base默认就是"/"。如果你准备发布到
https://<USERNAME>.gitlab.io/<REPO>/,也就是说你的仓库地址是https://gitlab.com/<USERNAME>/<REPO>,则将base设置为"/<REPO>/"。创建
.gitlab-ci.yml文件来配置 GitLab CI 工作流。
::: details 点击展开配置样例
# 选择你要使用的 docker 镜像image: node:14-busterpages:# 每当 push 到 main 分支时触发部署only:- main# 缓存 node_modulescache:paths:- node_modules/# 安装依赖并运行构建脚本script:- yarn --frozen-lockfile- yarn docs:build --dest publicartifacts:paths:- public
:::
::: tip 请参考 GitLab Pages 官方指南 来获取更多信息。 :::
Google Firebase
请确保你已经安装了 firebase-tools。
在你项目的根目录下创建
firebase.json和.firebaserc,并包含以下内容:
firebase.json:
{"hosting": {"public": "./docs/.vuepress/dist","ignore": []}}
.firebaserc:
{"projects": {"default": "<YOUR_FIREBASE_ID>"}}
- 在执行了
yarn docs:build或npm run docs:build后, 使用firebase deploy指令来部署。
::: tip 请参考 Firebase CLI 官方指南 来获取更多信息。 :::
Heroku
首先安装 Heroku CLI;
在这里 注册一个 Heroku 账号;
运行
heroku login并填写你的 Heroku 认证信息:
heroku login
- 在你的项目根目录中,创建一个名为
static.json的文件,并包含下述内容:
static.json:
{"root": "./docs/.vuepress/dist"}
这里是你项目的配置,请参考 heroku-buildpack-static 来获取更多信息。
Layer0
请查看 Layer0 Documentation > Framework Guides > VuePress 。
Netlify
前往 Netlify ,从 GitHub 创建一个新项目,并进行如下配置:
- Build Command:
yarn docs:build - Publish directory:
docs/.vuepress/dist
- Build Command:
设置 Environment variables 来选择 Node 版本:
NODE_VERSION: 14
点击 deploy 按钮。
Vercel
前往 Vercel ,从 GitHub 创建一个新项目,并进行如下配置:
- FRAMEWORK PRESET:
Other - BUILD COMMAND:
yarn docs:build - OUTPUT DIRECTORY:
docs/.vuepress/dist
- FRAMEWORK PRESET:
点击 deploy 按钮。
云开发 CloudBase
云开发 CloudBase 是一个云原生一体化的 Serverless 云平台,支持静态网站、容器等多种托管能力,并提供简便的部署工具 CloudBase Framework 来一键部署应用。
- 全局安装 CloudBase CLI :
npm install -g @cloudbase/cli
- 在项目根目录运行以下命令一键部署 VuePress 应用,在部署之前可以先 开通环境:
cloudbase init --without-templatecloudbase framework:deploy
CloudBase CLI 首先会跳转到控制台进行登录授权,然后将会交互式进行确认。
确认信息后会立即进行部署,部署完成后,可以获得一个自动 SSL,CDN 加速的网站应用,你也可以搭配使用 GitHub Action 来持续部署 GitHub 上的 VuePress 应用。
也可以使用 cloudbase init --template vuepress 快速创建和部署一个新的 VuePress 应用。
::: tip 更多详细信息请查看 CloudBase Framework 的部署项目示例 :::
