@142vip/vuepress
VuePress 使用的最佳实践,基于 vuepress-theme-hope 的封装
安装
包内已 bundled vuepress、vuepress-theme-hope;使用方通常无需单独声明 vuepress。
shell
# npm
npm install -D @142vip/vuepress
# pnpm
pnpm add -D @142vip/vuepress功能
defineVipVuepressConfig:默认locales['/'].lang/lang为zh-CN,补全bundler、favicon、shouldPrefetch- 可选
appBuildLog:构建时间 meta + 控制台版本日志(@142vip/vue/utils) getVipHopeTheme:基于 theme-hope 的默认插件与 Markdown 能力;未写时默认author/docsDir/docsBranch/contributorsdefineVipNavbarConfig/defineVipSidebarConfig:导航与侧栏createVipViteBuildPlugin:合并 Vite 构建参数(chunk 告警阈值)DocsSidebarLink/DocsSidebarGroup等侧栏配置类型- 内置 Mermaid、代码高亮语言、slimsearch 中文、复制代码
- bin:
vuepress(转发至 bundled CLI)
配置
单语言中文站一般不必手写 locales / lang:
ts
import { defineVipVuepressConfig, getVipHopeTheme } from '@142vip/vuepress'
export default defineVipVuepressConfig({
title: '我的文档',
description: '…',
theme: getVipHopeTheme({
navbar: [],
sidebar: {},
// author / docsDir / docsBranch / contributors 可省略,走包内默认
}),
}, {
// 可选:浏览器控制台打印版本与更新时间
appBuildLog: { version: '1.0.0' },
})包内默认(未传 locales 时)等价于:
text
locales: {
'/': {
lang: 'zh-CN',
},
}自定义示例(用户字段优先,缺 lang 时才补 zh-CN):
ts
export default defineVipVuepressConfig({
locales: {
'/': {
// lang 可省略,默认 zh-CN
title: '中文站',
},
'/en/': {
lang: 'en-US',
title: 'English',
},
},
theme: getVipHopeTheme({ navbar: [], sidebar: {} }),
})大文档站构建 chunk 告警:
ts
import { createVipViteBuildPlugin, defineVipVuepressConfig } from '@142vip/vuepress'
export default defineVipVuepressConfig({
plugins: [createVipViteBuildPlugin()],
// ...
})使用
开发与构建(使用包内 bin):
shell
pnpm vuepress dev docs
pnpm vuepress build docs代码块路径别名(Markdown <!-- @include -->):
ts
import { handleImportCodePath } from '@142vip/vuepress'
const resolver = handleImportCodePath([['@code', './code']])默认文档目录常量:VUEPRESS_DEFAULT_DOCS_DIR('docs')。
升级
shell
# 依赖更新
pnpm upgrade @142vip/vuepress参考
证书
Copyright (c) 2019-present, @142vip 储凡
仅供学习参考,商业使用请保留作者版权信息,作者不保证也不承担任何软件的使用风险。