Deploying
The following guides are based on some shared assumptions:
You are placing your docs inside the
docsdirectory of your project.You are using the default build output location (
.vitepress/dist).VitePress is installed as a local dependency in your project, and you have set up the following scripts in your
package.json:json{ "scripts": { "docs:build": "vitepress build docs", "docs:serve": "vitepress serve docs" } }1
2
3
4
5
6
TIP
If your site is to be served at a subdirectory (https://example.com/subdir/), then you have to set '/subdir/' as the base in your docs/.vitepress/config.js.
Example: If you're using Github (or GitLab) Pages and deploying to user.github.io/repo/, then set your base to /repo/.
Build and Test Locally
You may run this command to build the docs:
sh$ yarn docs:build1Once you've built the docs, you can test them locally by running:
sh$ yarn docs:serve1The
servecommand will boot up a local static web server that will serve the files from.vitepress/distathttp://localhost:5000. It's an easy way to check if the production build looks fine in your local environment.You can configure the port of the server by passing
--portas an argument.json{ "scripts": { "docs:serve": "vitepress serve docs --port 8080" } }1
2
3
4
5Now the
docs:servemethod will launch the server athttp://localhost:8080.
Netlify, Vercel, AWS Amplify, Cloudflare Pages, Render
Set up a new project and change these settings using your dashboard:
- Build Command:
yarn docs:build - Output Directory:
docs/.vitepress/dist - Node Version:
14(or above, by default it usually will be 14 or 16, but on Cloudflare Pages the default is still 12, so you may need to change that)
WARNING
Don't enable options like Auto Minify for HTML code. It will remove comments from output which have meaning to Vue. You may see hydration mismatch errors if they get removed.
GitHub Pages
Using GitHub Actions
Create a file named
deploy.ymlinside.github/workflowsdirectory of your project with the following content:yamlname: Deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 with: node-version: 16 cache: yarn - run: yarn install --frozen-lockfile - name: Build run: yarn docs:build - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: docs/.vitepress/dist1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26TIP
Please replace the corresponding branch name. For example, if the branch you want to build is
master, then you should replacemainwithmasterin the above file.Now commit your code and push it to the
mainbranch.Wait for actions to complete. Then select
gh-pagesbranch as GitHub Pages source in your repository settings. Now your docs will automatically deploy each time you push.
GitLab Pages
Using GitLab CI
Set
outDirindocs/.vitepress/config.jsto../public.Create a file called
.gitlab-ci.ymlin the root of your project with the content below. This will build and deploy your site whenever you make changes to your content:yamlimage: node:16 pages: cache: paths: - node_modules/ script: - yarn install - yarn docs:build artifacts: paths: - public only: - main1
2
3
4
5
6
7
8
9
10
11
12
13
Azure Static Web Apps
Follow the official documentation.
Set these values in your configuration file (and remove the ones you don't require, like
api_location):app_location:/output_location:docs/.vitepress/distapp_build_command:yarn docs:build
Firebase
Create
firebase.jsonand.firebasercat the root of your project:firebase.json:json{ "hosting": { "public": "docs/.vitepress/dist", "ignore": [] } }1
2
3
4
5
6.firebaserc:json{ "projects": { "default": "<YOUR_FIREBASE_ID>" } }1
2
3
4
5After running
yarn docs:build, run this command to deploy:shfirebase deploy1
Surge
After running
yarn docs:build, run this command to deploy:shnpx surge docs/.vitepress/dist1
Heroku
Follow documentation and guide given in
heroku-buildpack-static.Create a file called
static.jsonin the root of your project with the below content:json{ "root": "docs/.vitepress/dist" }1
2
3
颜画风的博客