用途:在编写、配置或调试导入 "vitepress" 的代码、运行 vitepress CLI 命令、编辑 .vitepress/config 或主题文件时提供参考。事实来源为准备好的包源码,行引用相对包根目录(如 dist/node/index.d.ts:2382)。
版本与依赖:版本 1.6.4,MIT。内置 Vue ^3.5.13、Vite ^5.4.14、shiki ^2.1.0、minisearch ^7,要求 Node.js 18+。VitePress v1 与 rolldown-vite 不兼容,开发服务器会打印错误并指向 VitePress v2。可选 peer 依赖:markdown-it-mathjax3(用于 markdown.math)、postcss。
入口:vitepress(Node、客户端与共享 API、配置辅助)、vitepress/client(客户端组合式函数如 useData、useRouter)、vitepress/theme(默认主题、useSidebar、useLocalNav)、vitepress/theme-without-fonts(不含内置字体的默认主题)。CLI 二进制为 vitepress,指向 bin/vitepress.js。
安装与命令:npm add -D vitepress;npx vitepress init;npx vitepress dev;npx vitepress build;npx vitepress preview。在当前目录使用时可省略 dev(仅 vitepress)。serve 是 preview 的别名。
常见任务:站点配置使用 .vitepress/config.ts 中的 defineConfig;defineConfig 针对默认主题提供类型,自定义主题使用 defineConfigWithTheme<CustomThemeConfig>。客户端运行时 API 包括 useData(page、frontmatter、isDark、hash)、useRouter、withBase。构建时数据加载可用 createContentLoader。仅浏览器组件可用 defineClientComponent 包裹,避免库在导入时访问 window/document 导致 SSG 构建失败。
最佳实践:归档与索引页使用 createContentLoader,避免手写加载器;在 Markdown 中保持图片和资源 URL 相对,以便 Vite 哈希与内联,主题组件中动态路径用 withBase();仅在主机可将 /foo 映射到 /foo.html 时启用 cleanUrls: true;使用重写时,相对链接须指向重写后的 URL 结构;动态路由 paths.js 加载器中,大负载经 content 传递而非 params,以减小客户端 JS;MPA 模式(mpa: true)下用 <script client> 实现交互,纯 <script setup> 仅作服务端模板;用 _render 钩子将页面排除出本地搜索;在 1.6.4 中,Theme.setup、Theme.NotFound、outlineTitle、lastUpdatedText、algolia 主题选项已弃用。
适用场景:VitePress 站点搭建、配置、主题扩展与调试。限制:资料未提供收费、价格、平台或效果等信息;未提供的内容均暂未提供,不应推断。