从零搭建一个组件库 -- 使用 vitepress 为组件编写文档

从零搭建一个组件库 -- 使用 vitepress 为组件编写文档

使用 vitepress 编写组件文档

  • packages 下创建 docs 目录
mkdir docs
cd docs
pnpm init
pnpm add -D vitepress
  • 在 docs 下创建 index.md
---
layout: home

hero:
  name: Vangle
  text:
  tagline: 基于 Vue 3,面向设计师和开发者的组件库
  actions:
    - theme: brand
      text: Why Vangle
      link: /articles/组件库环境搭建
    - theme: alt
      text: 快速开始
      link: /component/button

features:
  - icon: ⚡️
    title: 这是一个闪电图标
    details: wawawa
  - icon: 🖖
    title: 这是一个手掌图标
    details: good...
  - icon: 🛠️
    title: 这是一个修理图标
    details: cocococo
---
  • 在 package.json.添加一些 script 后运行 pnpm docs:dev
{
  "scripts": {
    "docs:dev": "vitepress dev .",
    "docs:build": "vitepress build .",
    "docs:serve": "vitepress serve ."
  }
}

在这里插入图片描述

  • 给 vitepress 添加配置,docs 目录下创建 .vitepress/config.ts,关于配置详情请参考官网
import type { UserConfig } from 'vitepress'

export const config: UserConfig = {
  title: 'Vangle',
  description: 'a Vue 3 based component library for designers and developers',
  themeConfig: {
    logo: '/images/vite.svg',
    footer: {
      message: 'Released under the MIT License.',
      copyright: 'Copyright © 2022-PRESENT vangleer and Vangle contributors'
    },
    algolia: {
      apiKey: 'your_api_key',
      indexName: 'index_name'
    },
    nav: [
      { text: '指南', link: '/guide/design' },
      { text: '组件', link: '/component/button' }
    ],
    socialLinks: [{ icon: 'github', link: 'https://github.com/vangleer' }],
    sidebar: {
      '/guide/': [],
      '/component/': [
        {
          text: 'Basic',
          items: [
            {
              text: 'Button',
              link: '/component/button'
            }
          ]
        }
      ]
    }
  }
}

export default config
  • 创建 guide 和 component 目录,在 component 目录下编写组件文档,button.md
  • 注意:文件的目录结构需要和 sidebar 的配置相对应
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值