CLI Commands
VitePress provides four main commands: dev, build, preview, and init.
Development Server
Start the dev server with hot module replacement:
bash
# In current directory (dev command is optional)
vitepress
# Or explicitly
vitepress dev
# With project in subdirectory
vitepress dev docsOptions:
| Option | Description |
|---|---|
--open [path] | Open browser on startup |
--port <port> | Specify port number |
--base <path> | Override base URL |
--cors | Enable CORS |
--strictPort | Exit if port is in use |
--force | Ignore cache and re-bundle |
bash
vitepress dev docs --port 3000 --openProduction Build
Build static files for production:
bash
vitepress build docsOptions:
| Option | Description |
|---|---|
--base <path> | Override base URL |
--target <target> | Transpile target (default: modules) |
--outDir <dir> | Output directory (relative to cwd) |
--assetsInlineLimit <n> | Asset inline threshold in bytes |
--mpa | Build in MPA mode (no client hydration) |
bash
vitepress build docs --outDir distPreview Production Build
Locally preview the production build:
bash
vitepress preview docsOptions:
| Option | Description |
|---|---|
--port <port> | Specify port number |
--base <path> | Override base URL |
bash
vitepress preview docs --port 4173Initialize Project
Start the setup wizard:
bash
vitepress initThis creates the basic file structure:
.vitepress/config.js- Configurationindex.md- Home page- Optional example pages
Package.json Scripts
Typical scripts configuration:
json
{
"scripts": {
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
}
}Key Points
- Dev server runs at
http://localhost:5173by default - Preview server runs at
http://localhost:4173 - Production output goes to
.vitepress/distby default - The
docsargument specifies the project root directory - Use
--baseto override base path without modifying config