mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
338 lines
11 KiB
338 lines
11 KiB
2 years ago
|
---
|
||
|
outline: deep
|
||
|
---
|
||
|
|
||
2 years ago
|
# Deploy Your VitePress Site
|
||
3 years ago
|
|
||
|
The following guides are based on some shared assumptions:
|
||
|
|
||
2 years ago
|
- The VitePress site is inside the `docs` directory of your project.
|
||
|
- You are using the default build output directory (`.vitepress/dist`).
|
||
2 years ago
|
- 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",
|
||
2 years ago
|
"docs:preview": "vitepress preview docs"
|
||
2 years ago
|
}
|
||
3 years ago
|
}
|
||
2 years ago
|
```
|
||
3 years ago
|
|
||
2 years ago
|
## Build and Test Locally
|
||
|
|
||
|
1. Run this command to build the docs:
|
||
|
|
||
|
```sh
|
||
|
$ npm run docs:build
|
||
|
```
|
||
|
|
||
|
2. Once built, preview it locally by running:
|
||
|
|
||
|
```sh
|
||
|
$ npm run docs:preview
|
||
|
```
|
||
|
|
||
|
The `preview` command will boot up a local static web server that will serve the output directory `.vitepress/dist` at `http://localhost:4173`. You can use this to make sure everything looks good before pushing to production.
|
||
|
|
||
|
3. You can configure the port of the server by passing `--port` as an argument.
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"scripts": {
|
||
|
"docs:preview": "vitepress preview docs --port 8080"
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
1 year ago
|
Now the `docs:preview` method will launch the server at `http://localhost:8080`.
|
||
2 years ago
|
|
||
|
## Setting a Public Base Path
|
||
3 years ago
|
|
||
2 years ago
|
By default, we assume the site is going to be deployed at the root path of a domain (`/`). If your site is going to be served at a sub-path, e.g. `https://mywebsite.com/blog/`, then you need to set the [`base`](../reference/site-config#base) option to `'/blog/'` in the VitePress config.
|
||
3 years ago
|
|
||
2 years ago
|
**Example:** If you're using Github (or GitLab) Pages and deploying to `user.github.io/repo/`, then set your `base` to `/repo/`.
|
||
|
|
||
2 years ago
|
## HTTP Cache Headers
|
||
3 years ago
|
|
||
2 years ago
|
If you have control over the HTTP headers on your production server, you can configure `cache-control` headers to achieve better performance on repeated visits.
|
||
3 years ago
|
|
||
2 years ago
|
The production build uses hashed file names for static assets (JavaScript, CSS and other imported assets not in `public`). If you inspect the production preview using your browser devtools' network tab, you will see files like `app.4f283b18.js`.
|
||
3 years ago
|
|
||
2 years ago
|
This `4f283b18` hash is generated from the content of this file. The same hashed URL is guaranteed to serve the same file content - if the contents change, the URLs change too. This means you can safely use the strongest cache headers for these files. All such files will be placed under `assets/` in the output directory, so you can configure the following header for them:
|
||
3 years ago
|
|
||
2 years ago
|
```
|
||
|
Cache-Control: max-age=31536000,immutable
|
||
|
```
|
||
3 years ago
|
|
||
1 year ago
|
::: details Example Netlify `_headers` file
|
||
3 years ago
|
|
||
2 years ago
|
```
|
||
|
/assets/*
|
||
|
cache-control: max-age=31536000
|
||
|
cache-control: immutable
|
||
|
```
|
||
3 years ago
|
|
||
1 year ago
|
Note: the `_headers` file should be placed in the [public directory](./asset-handling#the-public-directory) - in our case, `docs/public/_headers` - so that it is copied verbatim to the output directory.
|
||
2 years ago
|
|
||
2 years ago
|
[Netlify custom headers documentation](https://docs.netlify.com/routing/headers/)
|
||
3 years ago
|
|
||
2 years ago
|
:::
|
||
|
|
||
1 year ago
|
::: details Example Vercel config in `vercel.json`
|
||
2 years ago
|
|
||
|
```json
|
||
|
{
|
||
|
"headers": [
|
||
|
{
|
||
|
"source": "/assets/(.*)",
|
||
|
"headers": [
|
||
|
{
|
||
|
"key": "Cache-Control",
|
||
|
"value": "max-age=31536000, immutable"
|
||
|
}
|
||
|
]
|
||
2 years ago
|
}
|
||
2 years ago
|
]
|
||
|
}
|
||
|
```
|
||
3 years ago
|
|
||
2 years ago
|
Note: the `vercel.json` file should be placed at the root of your **repository**.
|
||
|
|
||
2 years ago
|
[Vercel documentation on headers config](https://vercel.com/docs/concepts/projects/project-configuration#headers)
|
||
3 years ago
|
|
||
2 years ago
|
:::
|
||
|
|
||
|
## Platform Guides
|
||
|
|
||
|
### Netlify / Vercel / Cloudflare Pages / AWS Amplify / Render
|
||
3 years ago
|
|
||
2 years ago
|
Set up a new project and change these settings using your dashboard:
|
||
3 years ago
|
|
||
2 years ago
|
- **Build Command:** `npm run docs:build`
|
||
2 years ago
|
- **Output Directory:** `docs/.vitepress/dist`
|
||
1 year ago
|
- **Node Version:** `18` (or above)
|
||
3 years ago
|
|
||
2 years ago
|
::: 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.
|
||
|
:::
|
||
3 years ago
|
|
||
2 years ago
|
### GitHub Pages
|
||
3 years ago
|
|
||
1 year ago
|
1. Create a file named `deploy.yml` inside `.github/workflows` directory of your project with some content like this:
|
||
3 years ago
|
|
||
2 years ago
|
```yaml
|
||
1 year ago
|
# Sample workflow for building and deploying a VitePress site to GitHub Pages
|
||
|
#
|
||
|
name: Deploy VitePress site to Pages
|
||
|
|
||
2 years ago
|
on:
|
||
1 year ago
|
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
|
||
|
# using the `master` branch as the default branch.
|
||
2 years ago
|
push:
|
||
1 year ago
|
branches: [main]
|
||
|
|
||
|
# Allows you to run this workflow manually from the Actions tab
|
||
|
workflow_dispatch:
|
||
|
|
||
|
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||
|
permissions:
|
||
|
contents: read
|
||
|
pages: write
|
||
|
id-token: write
|
||
|
|
||
|
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||
|
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||
|
concurrency:
|
||
|
group: pages
|
||
|
cancel-in-progress: false
|
||
|
|
||
2 years ago
|
jobs:
|
||
1 year ago
|
# Build job
|
||
|
build:
|
||
2 years ago
|
runs-on: ubuntu-latest
|
||
|
steps:
|
||
1 year ago
|
- name: Checkout
|
||
10 months ago
|
uses: actions/checkout@v4
|
||
2 years ago
|
with:
|
||
1 year ago
|
fetch-depth: 0 # Not needed if lastUpdated is not enabled
|
||
9 months ago
|
# - uses: pnpm/action-setup@v3 # Uncomment this if you're using pnpm
|
||
1 year ago
|
# - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
|
||
1 year ago
|
- name: Setup Node
|
||
10 months ago
|
uses: actions/setup-node@v4
|
||
2 years ago
|
with:
|
||
10 months ago
|
node-version: 20
|
||
1 year ago
|
cache: npm # or pnpm / yarn
|
||
|
- name: Setup Pages
|
||
10 months ago
|
uses: actions/configure-pages@v4
|
||
1 year ago
|
- name: Install dependencies
|
||
1 year ago
|
run: npm ci # or pnpm install / yarn install / bun install
|
||
1 year ago
|
- name: Build with VitePress
|
||
9 months ago
|
run: npm run docs:build # or pnpm docs:build / yarn docs:build / bun run docs:build
|
||
1 year ago
|
- name: Upload artifact
|
||
10 months ago
|
uses: actions/upload-pages-artifact@v3
|
||
2 years ago
|
with:
|
||
2 years ago
|
path: docs/.vitepress/dist
|
||
1 year ago
|
|
||
|
# Deployment job
|
||
|
deploy:
|
||
|
environment:
|
||
|
name: github-pages
|
||
|
url: ${{ steps.deployment.outputs.page_url }}
|
||
|
needs: build
|
||
|
runs-on: ubuntu-latest
|
||
|
name: Deploy
|
||
|
steps:
|
||
|
- name: Deploy to GitHub Pages
|
||
2 years ago
|
id: deployment
|
||
10 months ago
|
uses: actions/deploy-pages@v4
|
||
2 years ago
|
```
|
||
3 years ago
|
|
||
1 year ago
|
::: warning
|
||
|
Make sure the `base` option in your VitePress is properly configured. See [Setting a Public Base Path](#setting-a-public-base-path) for more details.
|
||
2 years ago
|
:::
|
||
|
|
||
1 year ago
|
2. In your repository's settings under "Pages" menu item, select "GitHub Actions" in "Build and deployment > Source".
|
||
3 years ago
|
|
||
1 year ago
|
3. Push your changes to the `main` branch and wait for the GitHub Actions workflow to complete. You should see your site deployed to `https://<username>.github.io/[repository]/` or `https://<custom-domain>/` depending on your settings. Your site will automatically be deployed on every push to the `main` branch.
|
||
3 years ago
|
|
||
2 years ago
|
### GitLab Pages
|
||
3 years ago
|
|
||
1 year ago
|
1. Set `outDir` in VitePress config to `../public`. Configure `base` option to `'/<repository>/'` if you want to deploy to `https://<username>.gitlab.io/<repository>/`.
|
||
2 years ago
|
|
||
1 year ago
|
2. Create a file named `.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:
|
||
3 years ago
|
|
||
2 years ago
|
```yaml
|
||
1 year ago
|
image: node:18
|
||
2 years ago
|
pages:
|
||
|
cache:
|
||
|
paths:
|
||
|
- node_modules/
|
||
|
script:
|
||
1 year ago
|
# - apk add git # Uncomment this if you're using small docker images like alpine and have lastUpdated enabled
|
||
2 years ago
|
- npm install
|
||
|
- npm run docs:build
|
||
2 years ago
|
artifacts:
|
||
|
paths:
|
||
|
- public
|
||
|
only:
|
||
|
- main
|
||
|
```
|
||
|
|
||
2 years ago
|
### Azure Static Web Apps
|
||
2 years ago
|
|
||
|
1. Follow the [official documentation](https://docs.microsoft.com/en-us/azure/static-web-apps/build-configuration).
|
||
|
|
||
|
2. Set these values in your configuration file (and remove the ones you don't require, like `api_location`):
|
||
|
|
||
|
- **`app_location`**: `/`
|
||
|
- **`output_location`**: `docs/.vitepress/dist`
|
||
2 years ago
|
- **`app_build_command`**: `npm run docs:build`
|
||
2 years ago
|
|
||
2 years ago
|
### Firebase
|
||
2 years ago
|
|
||
|
1. Create `firebase.json` and `.firebaserc` at the root of your project:
|
||
|
|
||
|
`firebase.json`:
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"hosting": {
|
||
|
"public": "docs/.vitepress/dist",
|
||
|
"ignore": []
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
`.firebaserc`:
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"projects": {
|
||
|
"default": "<YOUR_FIREBASE_ID>"
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
2. After running `npm run docs:build`, run this command to deploy:
|
||
2 years ago
|
|
||
|
```sh
|
||
|
firebase deploy
|
||
|
```
|
||
3 years ago
|
|
||
2 years ago
|
### Surge
|
||
3 years ago
|
|
||
2 years ago
|
1. After running `npm run docs:build`, run this command to deploy:
|
||
3 years ago
|
|
||
2 years ago
|
```sh
|
||
|
npx surge docs/.vitepress/dist
|
||
|
```
|
||
3 years ago
|
|
||
2 years ago
|
### Heroku
|
||
3 years ago
|
|
||
2 years ago
|
1. Follow documentation and guide given in [`heroku-buildpack-static`](https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-static).
|
||
3 years ago
|
|
||
2 years ago
|
2. Create a file called `static.json` in the root of your project with the below content:
|
||
3 years ago
|
|
||
2 years ago
|
```json
|
||
|
{
|
||
|
"root": "docs/.vitepress/dist"
|
||
|
}
|
||
|
```
|
||
2 years ago
|
|
||
2 years ago
|
### Edgio
|
||
2 years ago
|
|
||
2 years ago
|
Refer [Creating and Deploying a VitePress App To Edgio](https://docs.edg.io/guides/vitepress).
|
||
1 year ago
|
|
||
|
### Kinsta Static Site Hosting
|
||
|
|
||
5 months ago
|
You can deploy your VitePress website on [Kinsta](https://kinsta.com/static-site-hosting/) by following these [instructions](https://kinsta.com/docs/vitepress-static-site-example/).
|
||
8 months ago
|
|
||
|
### Stormkit
|
||
|
|
||
|
You can deploy your VitePress project to [Stormkit](https://www.stormkit.io) by following these [instructions](https://stormkit.io/blog/how-to-deploy-vitepress).
|
||
7 months ago
|
|
||
|
### Nginx
|
||
|
|
||
|
Here is a example of an Nginx server block configuration. This setup includes gzip compression for common text-based assets, rules for serving your VitePress site's static files with proper caching headers as well as handling `cleanUrls: true`.
|
||
|
|
||
|
```nginx
|
||
|
server {
|
||
|
gzip on;
|
||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||
|
|
||
|
listen 80;
|
||
|
server_name _;
|
||
|
index index.html;
|
||
|
|
||
|
location / {
|
||
|
# content location
|
||
|
root /app;
|
||
|
|
||
|
# exact matches -> reverse clean urls -> folders -> not found
|
||
|
try_files $uri $uri.html $uri/ =404;
|
||
|
|
||
|
# non existent pages
|
||
|
error_page 404 /404.html;
|
||
|
|
||
|
# a folder without index.html raises 403 in this setup
|
||
|
error_page 403 /404.html;
|
||
|
|
||
|
# adjust caching headers
|
||
|
# files in the assets folder have hashes filenames
|
||
|
location ~* ^/assets/ {
|
||
|
expires 1y;
|
||
|
add_header Cache-Control "public, immutable";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
This configuration assumes that your built VitePress site is located in the `/app` directory on your server. Adjust the `root` directive accordingly if your site's files are located elsewhere.
|
||
|
|
||
|
::: warning Do not default to index.html
|
||
|
The try_files resolution must not default to index.html like in other Vue applications. This would result in an invalid page state.
|
||
|
:::
|
||
|
|
||
|
Further information can be found in the [official nginx documentation](https://nginx.org/en/docs/), in these issues [#2837](https://github.com/vuejs/vitepress/discussions/2837), [#3235](https://github.com/vuejs/vitepress/issues/3235) as well as in this [blog post](https://blog.mehdi.cc/articles/vitepress-cleanurls-on-nginx-environment#readings) by Mehdi Merah.
|