Getting Started
This chapter will guide you through creating a VitePress site from scratch.
Prerequisites
- Node.js version 18 or higher.
- Terminal and code editor (such as VSCode).
Initialize Project
Create and enter a new directory
bashmkdir my-vitepress-site cd my-vitepress-siteInitialize npm project
bashnpm init -yInstall VitePress
bashnpm add -D vitepressRun initialization wizard
VitePress provides a convenient command-line tool to help you set up the basic structure.
bashnpx vitepress initThe wizard will ask a few questions, such as your documentation root directory, site title, and description. Answer according to your needs.
Project Structure
After initialization, your project structure will look roughly like this:
.
├── docs
│ ├── .vitepress
│ │ └── config.js # Configuration file
│ ├── api-examples.md
│ ├── markdown-examples.md
│ └── index.md # Home page
└── package.jsondocs: Where all Markdown source files and VitePress configuration are stored..vitepress: The "heart" of VitePress, containing configuration files, themes, and custom components.config.js: The core configuration file for the site.
Start Development Server
VitePress automatically adds some scripts to package.json.
Start development server
bashnpm run docs:devVisit the site
Open your browser and visit the URL displayed in the command line (usually
http://localhost:5173).
Now you should see your VitePress site running! Any changes you make to .md files in the docs directory will be instantly reflected in the browser through hot module replacement (HMR), without needing to refresh the page.
Build Static Site
When you're ready to deploy your site, you can run the following command:
npm run docs:buildThis generates the final static files in the .vitepress/dist directory, which you can deploy to any static hosting service.