VitePress Documentation
website·Indexed 40 days ago
https://vitepress.dev/A static site generator designed for building fast, content-centric sites. Documentation covers getting started, site configuration, routing, internationalization, and the default theme. Includes guides on using Vue in Markdown, build-time data loading, SSR compatibility, and deploying to platforms like Netlify, Vercel, and GitHub Pages.
What's inside VitePress
- VitePress is a Static Site Generator (SSG) designed for building fast, content-centric websites. It converts Markdown source content into static HTML pages by applying a theme. It is powered by Vite and Vue, making it particularly suitable for technical documentation, blogs, portfolios, and marketing sites.
Understand VitePress file-based routing
VitePress uses file-based routing where the directory structure of source Markdown files maps directly to the generated HTML pages. For example,index.mdbecomes/index.html(accessible as/), andguide/getting-started.mdbecomes/guide/getting-started.html.Use Vue features in VitePress Markdown
VitePress compiles each Markdown file into HTML and then processes it as a Vue Single-File Component (SFC). This allows you to use dynamic templating, Vue components, and custom logic directly within your Markdown files. Static content is automatically optimized and skipped during client-side hydration to reduce the JavaScript payload. All Vue usage must be SSR-compatible.Include external Markdown files or sections
Include the content of another Markdown file using the
<!--@@include: path-->directive. This supports nested inclusions and relative paths. You can prefix paths with@to reference the source root (usually the project root).Selection Methods:
- Line Ranges: Use
{start,end}(e.g.,{3,}for line 3 onwards,{,10}for up to line 10, or{1,10}). - VS Code Regions: Use
#region-nameto include content between<!-- #region name -->and<!-- #endregion name -->tags. - Header Anchors: Use
#anchor-idto include a specific section. The ID is the generated heading ID or a custom one defined via{#custom-id}.
Configuration:
markdown.include.silent: true: Logs a warning instead of throwing a build error if a file or region is missing.markdown.include.rebaseRelativeUrls: false: Makes relative links/images in the included file resolve relative to the including page instead of the included file's location.
# Docs <!-- Include relative file --> <!--@@include: ./parts/basics.md--> <!-- Include specific line range --> <!--@@include: ./parts/basics.md{3,10}--> <!-- Include VS Code region with line range --> <!--@@include: ./parts/basics.md#basic-usage{,2}--> <!-- Include by heading anchor --> <!--@@include: ./parts/basics.md#my-base-section-->- Line Ranges: Use
Isolate styles using the raw container
The::: rawcontainer wraps content in a<div class="vp-raw">to prevent style and router conflicts, which is useful for documenting component libraries. Style isolation is opt-in via a PostCSS plugin.npm add -D postcss// docs/postcss.config.mjs import { postcssIsolateStyles } from 'vitepress' export default { plugins: [ postcssIsolateStyles({ includeFiles: [/custom\.css/] // defaults to [/vp-doc\.css/, /base\.css/] }) ] }Exclude pages from local search
To prevent a page from appearing in the local search results, addsearch: falseto the page's frontmatter. If using a custom_renderfunction, this must be handled manually within that function.Create dynamic routes with a paths loader
Dynamic routes allow generating multiple pages from a single Markdown template using route parameters (e.g.,
[pkg].md). Because VitePress is a static site generator, every dynamic route file must have a corresponding paths loader file (e.g.,[pkg].paths.jsor[pkg].paths.ts).The loader must export a default object with a
pathsmethod that returns an array of objects containing aparamsproperty.// packages/[pkg].paths.js export default { paths() { return [ { params: { pkg: 'foo' } }, { params: { pkg: 'bar' } } ] } }Update static image syntax when migrating from VuePress
VitePress automatically handles thebaseconfiguration for static images, eliminating the need for the:src="$withBase(...)"syntax used in VuePress. You can now use standard Markdown image syntax for static assets. However, for dynamic images, you must still use thewithBasehelper.- <img :src="$withBase('/foo.png')" alt="foo"> + Migrate VitePress 0.x Frontmatter Configuration
Update the following frontmatter settings when migrating from VitePress 0.x:
- Home Page Layout: Change
home: truetolayout: home. Additional homepage settings are now available in the Home Page guide. - Footer: The
footeroption has been moved from individual page frontmatter to the globalthemeConfig.footerconfiguration.
- Home Page Layout: Change
Add attributes to custom containers
Custom containers support additional attributes using curly braces. For example,{open}makes a details block open by default, and{no-title}removes the title element (except fordetailsblocks).::: details Click me to toggle the code {open} ```js console.log('Hello, VitePress!'):::
::: tip {no-title} Just want to try it out? Skip to the Quickstart. :::
Set up basic internationalization (i18n) in VitePress
To support multiple languages, organize your documentation into locale-specific directories and configure thelocalesobject in your VitePress config. Therootlocale represents the default language, while other keys (e.g.,fr) correspond to the directory names for those languages.// docs/.vitepress/config.ts import { defineConfig } from 'vitepress' export default defineConfig({ locales: { root: { label: 'English', lang: 'en' }, fr: { label: 'French', lang: 'fr', // Added as `lang` attribute on <html> tag link: '/fr/guide' // Link for the navbar translations menu } } })// Recommended Directory Structure: // docs/ // ├─ es/ // │ └─ foo.md // ├─ fr/ // │ └─ foo.md // └─ foo.md
Scaffold a VitePress project using the Setup Wizard
VitePress provides a CLI setup wizard to help scaffold a basic project. You can run this in the current directory for a standalone site or in a nested directory (e.g.,./docs) if integrating into an existing project.# npm npx vitepress init # pnpm pnpm vitepress init # yarn yarn vitepress init # bun bun vitepress init