CLI Commands

Command-line interface for development, building, and previewing VitePress sites

VitePress provides four main commands: dev, build, preview, and init.

Development Server

Start the dev server with hot module replacement:

# In current directory (dev command is optional)
vitepress

# Or explicitly
vitepress dev

# With project in subdirectory
vitepress dev docs

Options:

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

vitepress dev docs --port 3000 --open

Production Build

Build static files for production:

Options:

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)

Preview Production Build

Locally preview the production build:

Options:

Option
Description

--port <port>

Specify port number

--base <path>

Override base URL

Initialize Project

Start the setup wizard:

This creates the basic file structure:

  • .vitepress/config.js - Configuration

  • index.md - Home page

  • Optional example pages

Package.json Scripts

Typical scripts configuration:

Key Points

  • Dev server runs at http://localhost:5173 by default

  • Preview server runs at http://localhost:4173

  • Production output goes to .vitepress/dist by default

  • The docs argument specifies the project root directory

  • Use --base to override base path without modifying config

Last updated

Was this helpful?