Deploying

The following guides are based on some shared assumptions:

  • You are placing your docs inside the docs directory of your project;
  • You are using the default build output location (.vuepress/dist);
  • VuePress is installed as a local dependency in your project, and you have setup the following npm scripts:
  1. {
  2. "scripts": {
  3. "docs:build": "vuepress build docs"
  4. }
  5. }

GitHub Pages

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

If you are deploying to https://<USERNAME>.github.io/, you can omit base as it defaults to "/".

If you are deploying to https://<USERNAME>.github.io/<REPO>/, (that is your repository is at https://github.com/<USERNAME>/<REPO&gt;), set base to "/<REPO>/".

  • Inside your project, create deploy.sh with the following content (with highlighted lines uncommented appropriately) and run it to deploy:
  1. #!/usr/bin/env sh
  2. # abort on errors
  3. set -e
  4. # build
  5. npm run docs:build
  6. # navigate into the build output directory
  7. cd docs/.vuepress/dist
  8. # if you are deploying to a custom domain
  9. # echo 'www.example.com' > CNAME
  10. git init
  11. git add -A
  12. git commit -m 'deploy'
  13. # if you are deploying to https://<USERNAME>.github.io
  14. # git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
  15. # if you are deploying to https://<USERNAME>.github.io/<REPO>
  16. # git push -f git@github.com:<USERNAME>/<REPO>.git master:gh-pages
  17. cd -

TIP

You can also run the above script in your CI setup to enable automatic deployment on each push.

GitHub Pages and Travis CI

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

If you are deploying to https://<USERNAME or GROUP>.github.io/, you can omit base as it defaults to "/".

If you are deploying to https://<USERNAME or GROUP>.github.io/<REPO>/, (that is your repository is at https://github.com/<USERNAME>/<REPO&gt;), set base to "/<REPO>/".

  • Create a file named .travis.yml in the root of your project.

  • Run yarn or npm install locally and commit the generated lockfile (i.e. yarn.lock or package-lock.json).

  • Use GitHub Pages deploy provider template and follow the travis documentationDeploying - 图1.

  1. language: node_js
  2. node_js:
  3. - lts/*
  4. install:
  5. - yarn install # npm ci
  6. script:
  7. - yarn docs:build # npm run docs:build
  8. deploy:
  9. provider: pages
  10. skip_cleanup: true
  11. local_dir: docs/.vuepress/dist
  12. github_token: $GITHUB_TOKEN # A token generated on GitHub allowing Travis to push code on you repository. Set in the Travis settings page of your repository, as a secure variable
  13. keep_history: true
  14. on:
  15. branch: master

GitLab Pages and GitLab CI

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

If you are deploying to https://<USERNAME or GROUP>.gitlab.io/, you can omit base as it defaults to "/".

If you are deploying to https://<USERNAME or GROUP>.gitlab.io/<REPO>/, (that is your repository is at https://gitlab.com/<USERNAME>/<REPO&gt;), set base to "/<REPO>/".

  • Set dest in .vuepress/config.js to public.

  • Create a file called .gitlab-ci.yml in the root of your project with the content below. This will build and deploy your site whenever you make changes to your content.

  1. image: node:9.11.1
  2. pages:
  3. cache:
  4. paths:
  5. - node_modules/
  6. script:
  7. - yarn install # npm install
  8. - yarn docs:build # npm run docs:build
  9. artifacts:
  10. paths:
  11. - public
  12. only:
  13. - master

Netlify

  • On NetlifyDeploying - 图2, setup up a new project from GitHub with the following settings:

  • Build Command: yarn docs:build or npm run docs:build

  • Publish directory: docs/.vuepress/dist

  • Hit the deploy button!

Google Firebase

  • Make sure you have firebase-toolsDeploying - 图3 installed.

  • Create firebase.json and .firebaserc at the root of your project with the following content:

firebase.json:

  1. {
  2. "hosting": {
  3. "public": "./docs/.vuepress/dist",
  4. "ignore": []
  5. }
  6. }

.firebaserc:

  1. {
  2. "projects": {
  3. "default": "<YOUR_FIREBASE_ID>"
  4. }
  5. }
  • After running yarn docs:build or npm run docs:build, deploy with the command firebase deploy.

Surge

  • First install surgeDeploying - 图4, if you haven’t already.

  • Run yarn docs:build or npm run docs:build.

  • Deploy to surge, by typing surge docs/.vuepress/dist.

You can also deploy to a custom domainDeploying - 图5 by adding surge docs/.vuepress/dist yourdomain.com.

Heroku

  • First install Heroku CLIDeploying - 图6.

  • Create a Heroku account hereDeploying - 图7.

  • Run heroku login and fill in your Heroku credentials:

  1. heroku login
  • Create a file called static.json in the root of your project with the content below:

static.json:

  1. {
  2. "root": "./docs/.vuepress/dist"
  3. }

This is the configuration of your site. See more at heroku-buildpack-staticDeploying - 图8.

  • Set up your Heroku git remote:
  1. # version change
  2. git init
  3. git add .
  4. git commit -m "My site ready for deployment."
  5. # creates a new app with a specified name
  6. heroku apps:create example
  7. # set buildpack for static sites
  8. heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git
  • Deploying Your Site
  1. # publish site
  2. git push heroku master
  3. # opens a browser to view the Dashboard version of Heroku CI
  4. heroku open

Now

Please check out Deploy an example VuePress site with NowDeploying - 图9.