当前位置:   article > 正文

使用VitePress静态网站生成器创建组件库文档网站并部署到GitHub_vitepress组件库文档

vitepress组件库文档

Vue3+TS+Vite开发组件库并发布到npm

网站在线预览:

Vue Amazing UI | Amazing UI Components LibraryAmazing UI 组件库https://themusecatcher.github.io/vue-amazing-ui/参考文档: 

一、安装依赖及配置

1、安装 vitepress

推荐使用 pnpm,安装pnpm:

npm install -g pnpm

安装vitepress: 

  1. pnpm add vitepress -D
  2. # or
  3. yarn add vitepress -D

2、在 package.json 中添加指令

在 script 中添加文档网站启动和打包指令,启动时指定端口 8000,并自动打开

  1. "scripts": {
  2. "docs:dev": "vitepress dev docs --port 8000 --open",
  3. "docs:build": "vitepress build docs"
  4. }

完整 package.json 文件如下: 

  1. {
  2. "name": "vue-amazing-ui",
  3. "version": "0.0.30",
  4. "private": false,
  5. "type": "module",
  6. "files": [
  7. "dist"
  8. ],
  9. "main": "./dist/vue-amazing-ui.umd.cjs",
  10. "module": "./dist/vue-amazing-ui.js",
  11. "exports": {
  12. "./dist/style.css": "./dist/style.css",
  13. "./css": "./dist/style.css",
  14. ".": {
  15. "import": "./dist/vue-amazing-ui.js",
  16. "require": "./dist/vue-amazing-ui.umd.cjs"
  17. }
  18. },
  19. "scripts": {
  20. "dev": "vite --port 9000 --open --force",
  21. "build": "run-p type-check build-only",
  22. "docs:dev": "vitepress dev docs --port 8000 --open",
  23. "docs:build": "vitepress build docs",
  24. "docs:deploy": "sh script/deploy.sh",
  25. "pub": "sh script/publish.sh",
  26. "preview": "vite preview",
  27. "build-only": "vite build",
  28. "type-check": "vue-tsc --noEmit",
  29. "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
  30. },
  31. "dependencies": {
  32. "@vuepic/vue-datepicker": "^4.5.1",
  33. "@vueuse/core": "^10.1.2",
  34. "@vueuse/integrations": "^10.1.2",
  35. "ant-design-vue": "^3.2.20",
  36. "core-js": "^3.30.2",
  37. "date-fns": "^2.30.0",
  38. "qrcode": "^1.5.3",
  39. "swiper": "^9.3.2",
  40. "vue": "^3.3.4",
  41. "vue-amazing-ui": "^0.0.30",
  42. "vue-router": "^4.2.1"
  43. },
  44. "devDependencies": {
  45. "@rushstack/eslint-patch": "^1.3.0",
  46. "@types/node": "^18.16.14",
  47. "@vitejs/plugin-vue": "^4.2.3",
  48. "@vue/eslint-config-typescript": "^11.0.3",
  49. "@vue/tsconfig": "^0.1.3",
  50. "eslint": "^8.41.0",
  51. "eslint-plugin-vue": "^9.14.0",
  52. "less": "^4.1.3",
  53. "npm-run-all": "^4.1.5",
  54. "prettier": "^2.8.8",
  55. "rollup-plugin-visualizer": "^5.9.0",
  56. "terser": "^5.17.6",
  57. "typescript": "~4.7.4",
  58. "unplugin-vue-components": "^0.25.0",
  59. "vite": "^4.3.8",
  60. "vitepress": "1.0.0-beta.1",
  61. "vue-tsc": "^1.6.5"
  62. },
  63. "description": "This template should help get you started developing with Vue Amazing UI in Vue 3.",
  64. "repository": {
  65. "type": "git",
  66. "url": "git+https://github.com/themusecatcher/vue-amazing-ui.git"
  67. },
  68. "keywords": [
  69. "Vue3",
  70. "TS",
  71. "Vite",
  72. "Amazing",
  73. "UI",
  74. "Components"
  75. ],
  76. "author": "theMuseCatcher",
  77. "license": "ISC",
  78. "bugs": {
  79. "url": "https://github.com/themusecatcher/vue-amazing-ui/issues"
  80. },
  81. "homepage": "https://github.com/themusecatcher/vue-amazing-ui#readme"
  82. }

3、创建文档网站目录和文件

①创建 docs/ 目录

②在 docs/ 下新建 index.md 首页文件

③在 docs/ 下新建 public/ 文件夹

用于存放各种静态资源,例如:网站logo、首页图片等 

4、 启动项目

 启动后项目会在自动 /docs 下生成 .vitepress/ 目录

pnpm docs:dev

二、编写组件库文档

1、创建相关文件及目录

在 docs/.vitepress 中

创建 config.ts 配置文件

创建 theme/ 文件夹

在 theme/ 中创建 index.ts 文件

在 theme/ 中创建 global.less 存放全局样式(使用 less 文件需要安装相应依赖 )

创建 utils/ 文件夹(用于存放自定义 ts 方法,一会首页自定义显示版本标签会用到)

(文档内使用了 less)安装 less 预处理器: 相关文档

pnpm add less -D

2、编写网站首页

首页配置参考文档

在 docs/index.md 中编写首页相关内容,其中 fetchVersion() 自定义方法用于在首页 tagline 后添加自定义版本标签

  1. ---
  2. layout: home
  3. title: Vue Amazing UI
  4. titleTemplate: Amazing UI Components Library
  5. hero:
  6. name: Vue Amazing UI
  7. text: Amazing UI 组件库
  8. tagline: 基于 Vue3 + TS + Vite 开发
  9. image:
  10. src: /logo-with-shadow.png
  11. alt: Vue Amazing UI
  12. actions:
  13. - theme: brand
  14. text: Get Started
  15. link: /guide/features
  16. - theme: alt
  17. text: View on GitHub
  18. link: https://github.com/themusecatcher/vue-amazing-ui
  19. - theme: alt
  20. text: View on NPM
  21. link: https://www.npmjs.com/package/vue-amazing-ui
  22. ---
  23. <script setup lang="ts">
  24. import { onMounted } from 'vue'
  25. import { fetchVersion } from './.vitepress/utils/fetchVersion'
  26. onMounted(() => {
  27. fetchVersion()
  28. })
  29. </script>

在 docs/.vitepress/utils/ 中创建 fetchVersion.ts 文件

  1. // 远程读取 github 仓库中 package.json 文件中的 version 版本号
  2. // 方式一:
  3. // 读取规则:https://api.github.com/repos/<username>/<repo>/contents/<file>?ref=<branch 可选,默认master>
  4. // return fetch('https://api.github.com/repos/themusecatcher/vue-amazing-ui/contents/package.json?ref=master', {
  5. // headers: {
  6. // // See https://docs.github.com/en/rest/overview/media-types
  7. // Accept: 'application/vnd.github.v3.raw',
  8. // // See https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api#authentication
  9. // // Authorization: 'token ${GITHUB_TOKEN}',
  10. // }
  11. // })
  12. // 方式二:
  13. // 读取规则:https://raw.githubusercontent.com/<username>/<repo>/<branch>/<file>
  14. export function fetchVersion() {
  15. return fetch('https://raw.githubusercontent.com/themusecatcher/vue-amazing-ui/master/package.json')
  16. .then(res => res.json())
  17. .then(json => json.version ?? '')
  18. .then(version => {
  19. if (!version) return
  20. const tagLineParagragh = document.querySelector('div.VPHero.has-image.VPHomeHero > div > div.main > p.tagline')
  21. const docsVersionSpan = document.createElement('samp')
  22. docsVersionSpan.classList.add('version-tag')
  23. docsVersionSpan.innerText = version
  24. tagLineParagragh?.appendChild(docsVersionSpan)
  25. })
  26. }

在 docs/.vitepress/theme/global.less 中写入标签样式

  1. .version-tag {
  2. font-size: 14px;
  3. line-height: 1.571;
  4. font-weight: bold;
  5. padding: 4px 6px;
  6. margin-left: 6px;
  7. background: #bd34fe;
  8. color: #FFF;
  9. border-radius: 10px;
  10. display: inline-block;
  11. vertical-align: top;
  12. margin-top: 4px;
  13. }

效果如下图,版本标签:0.0.30

3、编写文档全局样式

在 theme/global.less 中写入样式,以下样式皆源自 vite 官网项目中使用的全局样式,并稍加修改:

  1. /**
  2. * Colors
  3. * -------------------------------------------------------------------------- */
  4. :root {
  5. --vp-c-brand: #646cff;
  6. --vp-c-brand-light: #747bff;
  7. --vp-c-brand-lighter: #9499ff;
  8. --vp-c-brand-lightest: #bcc0ff;
  9. --vp-c-brand-dark: #535bf2;
  10. --vp-c-brand-darker: #454ce1;
  11. --vp-c-brand-dimm: rgba(100, 108, 255, 0.08);
  12. --c-brand: #646cff;
  13. --c-brand-light: #747bff;
  14. }
  15. /**
  16. * Component: Button
  17. * -------------------------------------------------------------------------- */
  18. :root {
  19. --vp-button-brand-border: var(--vp-c-brand-light);
  20. --vp-button-brand-text: var(--vp-c-white);
  21. --vp-button-brand-bg: var(--vp-c-brand);
  22. --vp-button-brand-hover-border: var(--vp-c-brand-light);
  23. --vp-button-brand-hover-text: var(--vp-c-white);
  24. --vp-button-brand-hover-bg: var(--vp-c-brand-light);
  25. --vp-button-brand-active-border: var(--vp-c-brand-light);
  26. --vp-button-brand-active-text: var(--vp-c-white);
  27. --vp-button-brand-active-bg: var(--vp-button-brand-bg);
  28. }
  29. /**
  30. * Component: Home
  31. * -------------------------------------------------------------------------- */
  32. :root {
  33. --vp-home-hero-name-color: transparent;
  34. --vp-home-hero-name-background: -webkit-linear-gradient(
  35. 120deg,
  36. #bd34fe 30%,
  37. #41d1ff
  38. );
  39. --vp-home-hero-image-background-image: linear-gradient(
  40. -45deg,
  41. #bd34fe 50%,
  42. #47caff 50%
  43. );
  44. --vp-home-hero-image-filter: blur(40px);
  45. }
  46. @media (min-width: 640px) {
  47. :root {
  48. --vp-home-hero-image-filter: blur(56px);
  49. }
  50. }
  51. @media (min-width: 960px) {
  52. :root {
  53. --vp-home-hero-image-filter: blur(72px);
  54. }
  55. }
  56. /**
  57. * Component: Custom Block
  58. * -------------------------------------------------------------------------- */
  59. :root {
  60. --vp-custom-block-tip-border: var(--vp-c-brand);
  61. --vp-custom-block-tip-text: var(--vp-c-brand-darker);
  62. --vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
  63. }
  64. .dark {
  65. --vp-custom-block-tip-border: var(--vp-c-brand);
  66. --vp-custom-block-tip-text: var(--vp-c-brand-lightest);
  67. --vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
  68. }
  69. /**
  70. * Component: Algolia
  71. * -------------------------------------------------------------------------- */
  72. .DocSearch {
  73. --docsearch-primary-color: var(--vp-c-brand) !important;
  74. }
  75. /**
  76. * VitePress: Custom fix
  77. * -------------------------------------------------------------------------- */
  78. /*
  79. Use lighter colors for links in dark mode for a11y.
  80. Also specify some classes twice to have higher specificity
  81. over scoped class data attribute.
  82. */
  83. .dark .vp-doc a,
  84. .dark .vp-doc a > code,
  85. .dark .VPNavBarMenuLink.VPNavBarMenuLink:hover,
  86. .dark .VPNavBarMenuLink.VPNavBarMenuLink.active,
  87. .dark .link.link:hover,
  88. .dark .link.link.active,
  89. .dark .edit-link-button.edit-link-button,
  90. .dark .pager-link .title {
  91. color: var(--vp-c-brand-lighter);
  92. }
  93. .dark .vp-doc a:hover,
  94. .dark .vp-doc a > code:hover {
  95. color: var(--vp-c-brand-lightest);
  96. opacity: 1;
  97. }
  98. .vp-doc a {
  99. font-weight: normal;
  100. }
  101. .vp-doc p {
  102. margin: 0;
  103. }
  104. /* Transition by color instead of opacity */
  105. .dark .vp-doc .custom-block a {
  106. transition: color 0.25s;
  107. }
  108. a:hover {
  109. text-decoration: none !important;
  110. }
  111. summary {
  112. font-weight: 600;
  113. &:hover {
  114. cursor: pointer;
  115. color: var(--vp-c-brand-lighter);
  116. }
  117. }
  118. svg {
  119. fill: var(--vp-c-text-1);
  120. }
  121. .VPNavBarTitle .title {
  122. transition: all 0.25s;
  123. &:hover {
  124. color: var(--vp-c-brand);
  125. }
  126. }
  127. .version-tag {
  128. font-size: 14px;
  129. line-height: 1.571;
  130. font-weight: bold;
  131. padding: 4px 6px;
  132. margin-left: 6px;
  133. background: #bd34fe;
  134. color: #FFF;
  135. border-radius: 10px;
  136. display: inline-block;
  137. vertical-align: top;
  138. margin-top: 4px;
  139. }

4、引入默认主题、全局样式与组件库

安装组件库

pnpm add vue-amazing-ui

在 theme/index.ts 中引入默认主题、全局样式并全局注册组件库

  1. import DefaultTheme from 'vitepress/theme'
  2. import './global.less' // global less
  3. import VueAmazingUI from 'vue-amazing-ui'
  4. import 'vue-amazing-ui/css'
  5. // import VueAmazingUI from '../../../dist/vue-amazing-ui'
  6. // import '../../../dist/style.css'
  7. export default {
  8. extends: DefaultTheme, // or ...DefaultTheme
  9. enhanceApp ({ app }) {
  10. app.use(VueAmazingUI)
  11. }
  12. }

5、 配置网站

在 docs/.vitepress/config.ts 中进行网站配置

  1. import { defineConfig } from 'vitepress'
  2. export default defineConfig({
  3. title: `Vue Amazing UI`,
  4. description: 'Amazing UI 组件库',
  5. base: '/vue-amazing-ui/',
  6. head: [ // 网站图标
  7. ['link', { rel: 'icon', type: 'image/svg+xml', href: 'logo.svg' }],
  8. // ['link', { rel: 'icon', type: 'image/x-icon', href: 'favicon.ico' }],
  9. ],
  10. appearance: true, // 默认 true,设为 false 则无法切换dark/light主题,可选 'dark' true false
  11. markdown: {
  12. lineNumbers: false // 是否显示行数,默认false
  13. },
  14. themeConfig: {
  15. logo: '/logo.svg',
  16. editLink: {
  17. pattern: 'https://github.com/themusecatcher/vue-amazing-ui/tree/master/docs/:path',
  18. text: 'Suggest changes to this page',
  19. },
  20. // 默认支持icon包括:'discord'|'facebook'|'github'|'instagram'|'linkedin'|'mastodon'|'slack'|'twitter'|'youtube'
  21. socialLinks: [
  22. { icon: 'github', link: 'https://github.com/themusecatcher/vue-amazing-ui' },
  23. // 自定义icon
  24. // {
  25. // icon: {
  26. // svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
  27. // },
  28. // link: 'https://www.npmjs.com/package/vue-amazing-ui'
  29. // }
  30. ],
  31. // search: { // vitepress 内置 search
  32. // provider: 'local'
  33. // },
  34. algolia: { // algolia 搜索服务 与 内置 search 可二选一
  35. appId: 'SHDNEYGA8Z',
  36. apiKey: '91419401b0b0efd31b610e54e5b97249',
  37. indexName: 'vue-amazing-ui'
  38. },
  39. footer: {
  40. message: 'Released under the MIT License.',
  41. copyright: 'Copyright © 2023-present The Muse Catcher',
  42. },
  43. nav: [
  44. { text: '组件', link: '/guide/features', activeMatch: '/guide/' },
  45. { text: '工具', link: '/utils/started', activeMatch: '/utils/' },
  46. {
  47. text: '链接',
  48. items: [
  49. { text: 'My Github', link: 'https://github.com/themusecatcher' },
  50. { text: 'My CSDN', link: 'https://blog.csdn.net/Dandrose?type=blog' },
  51. {
  52. items: [
  53. {
  54. text: 'vue',
  55. link: 'https://cn.vuejs.org/',
  56. },
  57. {
  58. text: 'vitepress',
  59. link: 'https://vitepress.dev/',
  60. }
  61. ]
  62. }
  63. ]
  64. }
  65. ],
  66. sidebar: {
  67. '/guide/': [
  68. {
  69. text: '指引',
  70. items: [
  71. {
  72. text: '特性',
  73. link: '/guide/features'
  74. },
  75. {
  76. text: '快速上手',
  77. link: '/guide/started'
  78. }
  79. ]
  80. },
  81. {
  82. text: '组件',
  83. items: [
  84. {
  85. text: '面包屑 Breadcrumb',
  86. link: '/guide/components/breadcrumb'
  87. },
  88. {
  89. text: '按钮 Button',
  90. link: '/guide/components/button'
  91. },
  92. {
  93. text: '走马灯 Carousel',
  94. link: '/guide/components/carousel'
  95. },
  96. {
  97. text: '级联选择 Cascader',
  98. link: '/guide/components/cascader'
  99. },
  100. {
  101. text: '多选框 Checkbox',
  102. link: '/guide/components/checkbox'
  103. },
  104. {
  105. text: '折叠面板 Collapse',
  106. link: '/guide/components/collapse'
  107. },
  108. {
  109. text: '倒计时 Countdown',
  110. link: '/guide/components/countdown'
  111. },
  112. {
  113. text: '日期选择 DatePicker',
  114. link: '/guide/components/datepicker'
  115. },
  116. {
  117. text: '对话框 Dialog',
  118. link: '/guide/components/dialog'
  119. },
  120. {
  121. text: '分割线 Divider',
  122. link: '/guide/components/divider'
  123. },
  124. {
  125. text: '空状态 Empty',
  126. link: '/guide/components/empty'
  127. },
  128. {
  129. text: '图片 Image',
  130. link: '/guide/components/image'
  131. },
  132. {
  133. text: '数字输入框 InputNumber',
  134. link: '/guide/components/inputnumber'
  135. },
  136. {
  137. text: '全局提示 Message',
  138. link: '/guide/components/message'
  139. },
  140. {
  141. text: '信息提示 Modal',
  142. link: '/guide/components/modal'
  143. },
  144. {
  145. text: '通知提醒框 Notification',
  146. link: '/guide/components/notification'
  147. },
  148. {
  149. text: '分页器 Pagination',
  150. link: '/guide/components/pagination'
  151. },
  152. {
  153. text: '进度条 Progress',
  154. link: '/guide/components/progress'
  155. },
  156. {
  157. text: '二维码 QRCode',
  158. link: '/guide/components/qrcode'
  159. },
  160. {
  161. text: '单选框 Radio',
  162. link: '/guide/components/radio'
  163. },
  164. {
  165. text: '评分 Rate',
  166. link: '/guide/components/rate'
  167. },
  168. {
  169. text: '选择器 Select',
  170. link: '/guide/components/select'
  171. },
  172. {
  173. text: '滑动输入条 Slider',
  174. link: '/guide/components/slider'
  175. },
  176. {
  177. text: '加载中 Spin',
  178. link: '/guide/components/spin'
  179. },
  180. {
  181. text: '步骤条 Steps',
  182. link: '/guide/components/steps'
  183. },
  184. {
  185. text: '触摸滑动插件 Swiper',
  186. link: '/guide/components/swiper'
  187. },
  188. {
  189. text: '开关 Switch',
  190. link: '/guide/components/switch'
  191. },
  192. {
  193. text: '表格 Table',
  194. link: '/guide/components/table'
  195. },
  196. {
  197. text: '标签页 Tabs',
  198. link: '/guide/components/tabs'
  199. },
  200. {
  201. text: '文字滚动 TextScroll',
  202. link: '/guide/components/textscroll'
  203. },
  204. {
  205. text: '时间轴 Timeline',
  206. link: '/guide/components/timeline'
  207. },
  208. {
  209. text: '文字提示 Tooltip',
  210. link: '/guide/components/tooltip'
  211. },
  212. {
  213. text: '上传 Upload',
  214. link: '/guide/components/upload'
  215. },
  216. {
  217. text: '播放器 Video',
  218. link: '/guide/components/video'
  219. },
  220. {
  221. text: '瀑布流 Waterfall',
  222. link: '/guide/components/waterfall'
  223. }
  224. ]
  225. }
  226. ],
  227. '/utils/': [
  228. {
  229. text: '指引',
  230. items: [
  231. {
  232. text: '快速上手',
  233. link: '/utils/started'
  234. }
  235. ]
  236. },
  237. {
  238. text: '工具',
  239. items: [
  240. {
  241. text: 'date 日期格式化',
  242. link: '/utils/date-format'
  243. },
  244. {
  245. text: 'raf 动画帧',
  246. link: '/utils/animation-frame'
  247. },
  248. {
  249. text: 'raf 定时器',
  250. link: '/utils/raf-timeout'
  251. },
  252. {
  253. text: 'throttle 节流',
  254. link: '/utils/throttle'
  255. },
  256. {
  257. text: 'debounce 防抖',
  258. link: '/utils/debounce'
  259. },
  260. {
  261. text: 'add 加法',
  262. link: '/utils/add'
  263. },
  264. {
  265. text: 'downloadFile 下载文件',
  266. link: '/utils/download-file'
  267. }
  268. ]
  269. }
  270. ]
  271. }
  272. }
  273. })

6、配置 Algolia 搜索

申请搜索服务

申请地址 

填写部署到公网的网站地址、邮箱和代码仓库地址,全部勾选,然后提交!

②等待申请通过的邮件

③回复邮件

I am the maintainer of the website, I can modify the code ~

④等待回复邮件

获取 appId、apiKey、indexName

⑤配置并引入 algolia 搜索服务

 在 docs/.vitepress/config.ts 中写入以下配置 

  1. import { defineConfig } from 'vitepress'
  2. export default defineConfig({
  3. themeConfig: {
  4. algolia: {
  5. appId: 'SHDNEYGA8Z',
  6. apiKey: '91419401b0b0efd31b610e54e5b97249',
  7. indexName: 'vue-amazing-ui'
  8. }
  9. }
  10. })

algolia 搜索效果如下图:

网站整体目录结构如下图:

网站首页效果如下图:

 三、网站内容目录

1、创建内容目录文件

在 docs/ 下新建 /guide 文件夹

注意:目录结构需要与 docs/.vitepress/config.ts 配置文件中的 sidebar 属性相对应

创建 components/ 目录用于存放每个组件对应的文档页

创建 features.md 和 started.md 用与编写网站指引中的 特性 和 快速上手页面

features.md 文件:

  1. # 特性
  2. ## 简要介绍
  3. 该组件库采用 Vue3 + TS + Vite3 + Less 实现!
  4. 开箱即用!
  5. ## 三种使用方式
  6. - 全局引入所有组件
  7. - 按需引入部分组件
  8. - git clone [vue-amazing-ui](https://github.com/themusecatcher/vue-amazing-ui) 到本地后,从 packages 下单独拷贝单文件组件 (SFC) 到项目内使用

started.md 文件:

  1. # 快速上手
  2. ## 安装
  3. **With PNPM**
  4. ```bash
  5. $ pnpm i vue-amazing-ui
  6. # or
  7. $ pnpm add vue-amazing-ui
  8. ```
  9. **With Yarn**
  10. ```bash
  11. $ yarn add vue-amazing-ui
  12. ```
  13. **With NPM**
  14. ```bash
  15. $ npm i vue-amazing-ui
  16. ```
  17. ## 使用
  18. **Global**
  19. ```ts
  20. import { createApp } from 'vue'
  21. import App from './App.vue'
  22. import VueAmazingUI from 'vue-amazing-ui'
  23. import 'vue-amazing-ui/css'
  24. const app = createApp(App)
  25. app.use(VueAmazingUI)
  26. app.mount('#app')
  27. ```
  28. **Local**
  29. ```vue
  30. <script setup lang="ts">
  31. import { Button } from 'vue-amazing-ui'
  32. import 'vue-amazing-ui/css'
  33. </script>
  34. <template>
  35. <Button></Button>
  36. </template>
  37. ```

2、创建各个组件文档

在 components/ 目录下分别创建组件对应 md 文件

例如:编写 面包屑 breadcrumb 组件文档:

  1. # 面包屑 Breadcrumb
  2. <br/>
  3. *显示当前页面在系统层级结构中的位置,并能向上返回*
  4. ## 何时使用
  5. - 当系统拥有超过两级以上的层级结构时
  6. - 当需要告知用户『你在哪里』时
  7. - 当需要向上导航的功能时
  8. <script setup lang="ts">
  9. const routes = [
  10. {
  11. path: '/first', // 路由地址
  12. query: { id: 1, tab: 2 }, // 路由参数
  13. name: '一级路由' // 路由名称
  14. },
  15. {
  16. path: '/second',
  17. name: '二级路由'
  18. },
  19. {
  20. path: '/third',
  21. name: '三级路由三级路由三级路由三级路由'
  22. }
  23. ]
  24. </script>
  25. ## 基本使用
  26. <Breadcrumb :routes="routes" />
  27. ::: details Show Code
  28. ```vue
  29. <script setup lang="ts">
  30. const routes = [
  31. {
  32. path: '/first', // 路由地址
  33. query: { id: 1, tab: 2 }, // 路由参数
  34. name: '一级路由' // 路由名称
  35. },
  36. {
  37. path: '/second',
  38. name: '二级路由'
  39. },
  40. {
  41. path: '/third',
  42. name: '三级路由三级路由三级路由三级路由'
  43. }
  44. ]
  45. </script>
  46. <template>
  47. <Breadcrumb :routes="routes" />
  48. </template>
  49. ```
  50. :::
  51. ## 自定义分隔符
  52. <Breadcrumb :routes="routes" separator="/" />
  53. ::: details Show Code
  54. ```vue
  55. <script setup lang="ts">
  56. const routes = [
  57. {
  58. path: '/first', // 路由地址
  59. query: { id: 1, tab: 2 }, // 路由参数
  60. name: '一级路由' // 路由名称
  61. },
  62. {
  63. path: '/second',
  64. name: '二级路由'
  65. },
  66. {
  67. path: '/third',
  68. name: '三级路由三级路由三级路由三级路由'
  69. }
  70. ]
  71. </script>
  72. <template>
  73. <Breadcrumb :routes="routes" separator="/" />
  74. </template>
  75. ```
  76. :::
  77. ## 自定义样式
  78. <Breadcrumb :routes="routes" :font-size="16" />
  79. ::: details Show Code
  80. ```vue
  81. <script setup lang="ts">
  82. const routes = [
  83. {
  84. path: '/first', // 路由地址
  85. query: { id: 1, tab: 2 }, // 路由参数
  86. name: '一级路由' // 路由名称
  87. },
  88. {
  89. path: '/second',
  90. name: '二级路由'
  91. },
  92. {
  93. path: '/third',
  94. name: '三级路由三级路由三级路由三级路由三级路由'
  95. }
  96. ]
  97. </script>
  98. <template>
  99. <Breadcrumb :routes="routes" :font-size="16" />
  100. </template>
  101. ```
  102. :::
  103. ## 新页面打开目标链接
  104. <Breadcrumb :routes="routes" target="_blank" />
  105. ::: details Show Code
  106. ```vue
  107. <script setup lang="ts">
  108. const routes = [
  109. {
  110. path: '/first', // 路由地址
  111. query: { id: 1, tab: 2 }, // 路由参数
  112. name: '一级路由' // 路由名称
  113. },
  114. {
  115. path: '/second',
  116. name: '二级路由'
  117. },
  118. {
  119. path: '/third',
  120. name: '三级路由三级路由三级路由三级路由'
  121. }
  122. ]
  123. </script>
  124. <template>
  125. <Breadcrumb :routes="routes" target="_blank" />
  126. </template>
  127. ```
  128. :::
  129. ## APIs
  130. 参数 | 说明 | 类型 | 默认值 | 必传
  131. -- | -- | -- | -- | --
  132. routes | 路由数组 | Route[] | [] | true
  133. fontSize | 字体大小,单位px | number | 14 | false
  134. height | 面包屑高度 | number | 36 | false
  135. maxWidth | 文本最大显示宽度,超出后显示省略号,单位px | 180 | false
  136. separator | 分隔符,默认''时为箭头 | string | '' | false
  137. target | 如何打开目标URL | '_self' &#124; '_blank' | '_self' | false
  138. ## Route Type
  139. 名称 | 说明 | 类型 | 必传
  140. -- | -- | -- | --
  141. path | 路由地址 | string | true
  142. query | 路由查询参数 | [propName: string]: any | false
  143. name | 路由名称 | string | true

四、打包静态网站并部署到 GitHub

1、创建脚本目录

在项目根目录 创建 script/ 目录,主要用于存放各种脚本文件,方便日后自动化开发流程!

创建 deploy.sh 用于打包静态网站,并部署到 Github

创建 publish.sh 用于打包升级组件库 ,并发布到 npm,同时自动升级项目内组件库依赖版本到最新

deploy.sh 文件:

  1. # /bin/bash
  2. # 确保脚本抛出遇到的错误
  3. set -e
  4. # 重新打包组件库
  5. pnpm build
  6. # 打包生成静态文件
  7. pnpm docs:build
  8. # 进入待发布的 dist/ 目录
  9. cd docs/.vitepress/dist
  10. git init
  11. git add .
  12. git commit -m 'deploy'
  13. # 部署到 https://<username>.github.io/<repo>
  14. git push -f git@github.com:themusecatcher/vue-amazing-ui.git master:github-pages
  15. # 提交所有代码到github
  16. cd ../../../
  17. git add .
  18. git cm -m 'update'
  19. git push

publish.sh 文件(需提前登录 npm 账户,否则无法直接发布): 

  1. # /bin/bash
  2. # 确保脚本抛出遇到的错误
  3. set -e
  4. # 读取package.json中的version
  5. version=`jq -r .version package.json`
  6. # 打包构建
  7. pnpm build
  8. # 提交代码到github
  9. git add .
  10. git commit -m "update $version"
  11. git push
  12. # 发布到npm,pnpm(高性能的npm)
  13. pnpm publish
  14. # 升级 vue-amazing-ui 依赖版本
  15. pnpm up vue-amazing-ui@$version
  16. # 提交版本更新代码到github
  17. git add .
  18. git cm -m "update $version"
  19. git push

2、 在 package.json 添加指令

  1. "scripts": {
  2. "docs:deploy": "sh script/deploy.sh",
  3. "pub": "sh script/publish.sh"
  4. }

3、打包部署

pnpm docs:deploy

4、配置 github

5、查看网站

save 成功之后,点击 Visit site 打开查看网站:

查看网站内容: 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/574698
推荐阅读
相关标签
  

闽ICP备14008679号