0

I want to build a blog with vuepress, and want to publish it to my server and github page. Like www.codingyang.com and https://github.com/Rackar/codingyang, but in the config.js, 'base' will be set to '/' and '/codingyang', to make the url resource correct.

Can I change different shell to build with different congfig.base ?

    "docs:build": "vuepress build docs && node utils/bd_hm.js",
    "docs:build:gitpage": "vuepress build docs --codingyang && node utils/bd_hm.js",
    "docs:push:gitpage": "push-dir --dir=docs/.vuepress/dist --branch=gh-pages"

like use 'docs:build' to build dist/ with base = '/' ,and copy that to my server.

use 'docs:build:gitpage' && 'docs:push:gitpage' to set base = 'codingyang ', and use them in github Actions and github Pages for other developers?

Can I use additional parameters or determine the environment scripts to do such thing?

Rackar
  • 15
  • 5

1 Answers1

1

For now, I believe you can set the base value depending on an environment variable:

module.exports = {
  base: process.env.VUEPRESS_BASE || '/'
}

And config the environment variable in package.json:

"scripts": {
  "docs:build": "vuepress build docs && node utils/bd_hm.js",
  "docs:build:gitpage": "VUEPRESS_BASE="/codingyang/" && vuepress build docs --codingyang && node utils/bd_hm.js"
}

Reference:

  1. Issue #560
  2. How to set environment variable from within package.json
Sun Haoran
  • 516
  • 1
  • 5
  • 13
  • 1
    Thank you very much. 感谢老铁。 ``` "docs:build:gitpage": "export VUEPRESS_BASE=/codingyang/|| set VUEPRESS_BASE=/codingyang/&&vuepress build docs && node utils/bd_hm.js" ``` Following your reply and the references, I got this worked! – Rackar Oct 15 '19 at 16:58