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 (`.vitepress/dist`);
- VitePress is installed as a local dependency in your project, and you have setup the following npm scripts:
- You are placing your docs inside the `docs` directory 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 setup the following scripts in your `package.json`:
```json
{
@ -15,26 +15,29 @@ The following guides are based on some shared assumptions:
}
```
## Build and test locally
::: tip
You may run `yarn docs:build` command to build the docs.
If your site is to be served at a subdirectory (`https://example.com/subdir/`), then you have to set `'/subdir/'` as the [`base`](../config/app-configs#base) in your `docs/.vitepress/config.js`.
```bash
$ yarn docs:build
```
:::
By default, the build output will be placed at `.vitepress/dist`. You may deploy this `dist` folder to any of your preferred platforms.
## Build and Test Locally
Once you've built the docs, you may test them locally by running `yarn docs:serve` command.
- You may run this command to build the docs:
```bash
```sh
$ yarn docs:build
```
- Once you've built the docs, you can test them locally by running:
```sh
$ yarn docs:serve
```
The `serve` command will boot up local static web server that serves the files from `.vitepress/dist` at `http://localhost:5000`. It's an easy way to check if the production build looks OK in your local environment.
The `serve` command will boot up a local static web server that will serve the files from `.vitepress/dist` at `http://localhost:5000`. It's an easy way to check if the production build looks fine in your local environment.
You may configure the port of the server by passing `--port` flag as an argument.
- You can configure the port of the server by passing `--port` as an argument.
```json
{
@ -46,91 +49,67 @@ You may configure the port of the server by passing `--port` flag as an argument
Now the `docs:serve` method will launch the server at `http://localhost:8080`.
## GitHub Pages
1. Set the correct `base` in `docs/.vitepress/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>/`, for example your repository is at `https://github.com/<USERNAME>/<REPO>`, then set `base` to `'/<REPO>/'`.
Set up a new project and change these settings using your dashboard:
2. Inside your project, create `deploy.sh` with the following content (with highlighted lines uncommented appropriately), and run it to deploy:
- **Build Command:**`yarn docs:build`
- **Output Directory:**`docs/.vitepress/dist`
```bash{13,20,23}
#!/usr/bin/env sh
::: 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.
:::
# abort on errors
set -e
## GitHub Pages
# build
npm run docs:build
### Using GitHub Actions
# navigate into the build output directory
cd docs/.vitepress/dist
1. Create a file named `deploy.yml` inside `.github/workflow` directory of your project with the following content:
# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME
```yaml
name: Deploy
git init
git add -A
git commit -m 'deploy'
on:
push:
branches:
- main
# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git 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
# if you are deploying to https://<USERNAME>.github.io/<REPO>
You can also run the above script in your CI setup to enable automatic deployment on each push.
:::
## GitHub Pages and Travis CI
1. Set the correct `base` in `docs/.vitepress/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>/`, for example your repository is at `https://github.com/<USERNAME>/<REPO>`, then set `base` to `'/<REPO>/'`.
2. Now commit your code and push it to the `main` branch.
2. Create a file named `.travis.yml` in the root of your project.
3. Wait for actions to complete. Then select `gh-pages` branch as GitHub Pages source in your repository settings. Now your docs will automatically deploy each time you push.
3. Run `yarn` or `npm install` locally and commit the generated lockfile (that is `yarn.lock` or `package-lock.json`).
## GitLab Pages
4. Use the GitHub Pages deploy provider template, and follow the [Travis CI documentation](https://docs.travis-ci.com/user/deployment/pages).
```yaml
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/.vitepress/dist
# 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.
github_token: $GITHUB_TOKEN
keep_history: true
on:
branch: main
```
## GitLab Pages and GitLab CI
### Using GitLab CI
1. Set the correct `base` in `docs/.vitepress/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>/`, for example your repository is at `https://gitlab.com/<USERNAME>/<REPO>`, then set `base` to `'/<REPO>/'`.
If you are deploying to `https://<USERNAME or GROUP>.gitlab.io/<REPO>/` (your repository is at `https://gitlab.com/<USERNAME>/<REPO>`), then set `base` to `'/<REPO>/'`.
2. Set `outDir` in `.vitepress/config.js` to `../public`.
2. Set `outDir` in `docs/.vitepress/config.js` to `../public`.
3. 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:
@ -141,8 +120,8 @@ pages:
paths:
- node_modules/
script:
- yarn install # npm install
- yarn docs:build # npm run docs:build
- yarn install
- yarn docs:build
artifacts:
paths:
- public
@ -150,27 +129,26 @@ pages:
- main
```
## Netlify
1. On [Netlify](https://www.netlify.com/), setup up a new project from GitHub with the following settings:
## Azure Static Web Apps
- **Build Command:**`vitepress build docs` or `yarn docs:build` or `npm run docs:build`
- **Publish directory:**`docs/.vitepress/dist`
1. Follow the [official documentation](https://docs.microsoft.com/en-us/azure/static-web-apps/build-configuration).
2. Hit the deploy button.
2. Set these values in your configuration file:
## Google Firebase
- **`app_location`**: `/`
- **`output_location`**: `docs/.vitepress/dist`
- **`app_build_command`**: `yarn docs:build`
1. Make sure you have [firebase-tools](https://www.npmjs.com/package/firebase-tools) installed.
## Firebase
2. Create `firebase.json` and `.firebaserc` at the root of your project with the following content:
1. Create `firebase.json` and `.firebaserc` at the root of your project:
`firebase.json`:
```json
{
"hosting": {
"public": "./docs/.vitepress/dist",
"public": "docs/.vitepress/dist",
"ignore": []
}
}
@ -178,7 +156,7 @@ pages:
`.firebaserc`:
```js
```json
{
"projects": {
"default": "<YOUR_FIREBASE_ID>"
@ -186,137 +164,32 @@ pages:
}
```
3. After running `yarn docs:build` or `npm run docs:build`, deploy using the command `firebase deploy`.
2. After running `yarn docs:build`, run this command to deploy:
## Surge
1. First install [surge](https://www.npmjs.com/package/surge), if you haven’t already.
```sh
firebase deploy
```
2. Run `yarn docs:build` or `npm run docs:build`.
## Surge
3. Deploy to surge by typing `surge docs/.vitepress/dist`.
1. After running `yarn docs:build`, run this command to deploy:
You can also deploy to a [custom domain](https://surge.sh/help/adding-a-custom-domain) by adding `surge docs/.vitepress/dist yourdomain.com`.
# opens a browser to view the Dashboard version of Heroku CI
$ heroku open
```
## Vercel
To deploy your VitePress app with a [Vercel for Git](https://vercel.com/docs/concepts/git), make sure it has been pushed to a Git repository.
Go to https://vercel.com/new and import the project into Vercel using your Git of choice (GitHub, GitLab or BitBucket). Follow the wizard to select the project root with the project's `package.json` and override the build step using `yarn docs:build` or `npm run docs:build` and the output dir to be `./docs/.vitepress/dist`
After your project has been imported, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly "main") will result in a Production Deployment.
Once deployed, you will get a URL to see your app live, such as the following: https://vitepress.vercel.app
## Layer0
See [Creating and Deploying a VitePress App with Layer0](https://docs.layer0.co/guides/vitepress).
## Cloudflare Pages
1. Go to [Cloudflare dashboard](https://dash.cloudflare.com/) > Account Home > Pages and selecting **Create a project**.
2. You will see three options, just select first **Connect to a git provider**.
3. Click Connect GitHub or Connect GitLab. Then select the repo you want to deploy.
4. Set up build docs command, like `npm run build` or `npm run docs:build`.
5. Now deploy, you will get a domain like `my-project.pages.dev`.
::: warning Do not Auto Minify HTML
If you want or are using Cloudflare's Auto minify feature, you should not check the html box.
With Auto Minify, Cloudflare will automatically remove the comments in the html file, however, html comments for Vue has meanings. For example, it works as a placeholder for `v-if`.
If it gets removed, then you will probably see a hydration mismatch error.
:::
## Azure Static Web App using GitHub Actions
1. Go to https://portal.azure.com
2. Create [Azure Static Web App](https://azure.microsoft.com/en-us/services/app-service/static/) free tier.
3. Don't connect GitHub to Azure Static Web App.
4. When the resource is deployed open it click on 'Manage deployment token' and copy the token.
5. Open your GitHub repository and go to 'Settings' -> 'Secrets' -> 'Actions' -> 'New repository secret'
6. Enter name 'AZURE_STATIC_WEB_APP_TOKEN'
7. Paste deployment token from Azure Static Web App
8. In GiHub repository create '.github/workflows/cd.yml' and fill it like this: