Skip to content

VitePress实战

快速开始

官网文档地址

示例

代码分组

VitePress 可以单独使用,也可以安装到现有项目中。在这两种情况下,都可以使用以下方式安装它:

sh
$ npm add -D vitepress
sh
$ pnpm add -D vitepress
sh
$ yarn add -D vitepress
sh
$ yarn add -D vitepress vue
sh
$ bun add -D vitepress

INFO

This is an info box.

TIP

This is a tip.

WARNING

This is a warning.

DANGER

This is a dangerous warning.

Details

This is a details block.

折叠

遇到了 missing peer deps 警告?

如果使用 PNPM,会注意到对 @docsearch/js 的 missing peer deps 警告。这不会影响 VitePress 运行。如果希望禁止显示此警告,请将以下内容添加到 package.json

json
"pnpm": {
  "peerDependencyRules": {
    "ignoreMissing": [
      "@algolia/client-search",
      "search-insights"
    ]
  }
}

引用

将需要回答几个简单的问题:

  Welcome to VitePress!

  Where should VitePress initialize the config?
  ./docs

  Site title:
  My Awesome Project

  Site description:
  A VitePress Site

  Theme:
 Default Theme (Out of the box, good-looking docs)
 Default Theme + Customization
 Custom Theme

注意

在 Markdown 链接中,base 会自动添加到 URL 前面。这意味着,如果想链接到 base 之外的页面,则链接中需要类似 ../../pure.html 的内容(由浏览器相对于当前页面解析)。

或者,可以直接使用锚标记语法:

md
<a href="/pure.html" target="_self">Link to pure.html</a>