npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yuci/vitepress-markdown-demo-block

v0.1.0

Published

A Vitepress Markdown Plugin

Readme

vitepress-markdown-demo-block

一个基于 vitepressmarkdown 工具,主要用于组件库文档中的组件展示和源码

案例

Alt text

基础目录结构

.
├─ .vitepress
│  ├─ config.ts
│  ├─ theme
│  │    ├─ index.ts
├─ demos
│  ├─ avatar
│  │     ├─ basic.vue
│  │     ├─ others.vue
│  ├─ button
│  │─ table
│  └─ index.ts
...

组件注册

vitepress 工程下找到 .vitepress/config.ts 文件,加入一下代码:

import { defineConfig } from 'vitepress'
import demoBlockPlugin from 'vitepress-markdown-demo-block'

export default defineConfig({
  markdown: {
    config: (md) => md.use(demoBlockPlugin)
    // config: (md) => md.use(demoBlockPlugin, 'myDemosDir')
  }
})

md.use() 可传两个参数,第一个参数为当前插件即 demoBlockPlugin , 第二个参数选传, 默认值为 demos ,即存放组件 demo 的文件夹,如果你存放组件的目录不叫 demos ,则须 将传入第二个字段,否则无法正确加载组件。

.vitepress/theme/index.ts 文件中去全局注册

import DefaultTheme from 'vitepress/theme'
import DemoBlockContainer from 'vitepress-markdown-demo-block/block'
import Demos from 'demos' // 你的demos路径

export default {
  ...DefaultTheme,
  enhanceApp({ app }) {
    app.use(Demos) // 全局注册demos中的组件
    app.component('DemoBlockContainer', DemoBlockContainer) // 全局注册DemoBlockContainer
  }
}

demos 下的文件做全局注册,仅供参考

import { startCase } from 'lodash-es'

const modules = import.meta.glob('./**/*.vue')

export default {
  install: (app) => {
    // eslint-disable-next-line guard-for-in
    for (const path in modules) {
      const index = path.indexOf('.vue')
      const newPath = path.substring(0, index)
      const name = startCase(newPath).split(' ').join('')
      modules[path]().then((mod) => {
        app.component(name, mod.default) // demos下的组件全局注册
      })
    }
  }
}

开始使用

npm install vitepress-markdown-demo-block -D

任意新建一个 md 文件,components.md

:::demo 按钮基本用法

<ButtonBasic />

:::

:::demo 我们提供多种预设色彩的标签样式,通过 `color` 设置不同颜色。如果预设值不能满足你的需求,`color` 字段也可以设置自定义色值。

<tab-color />

:::

:::后必须写上 demodemo 后是组件的使用说明

:::中包裹组件的命名要求:目录名+文件名Button为目录名,Basicbasic.vue文件

须遵循 vue 组件写法规范,以下写法都可:

  • <MyComponent></MyComponent>
  • <my-component></my-component>
  • <MyComponent />
  • <my-component />

Issues

有任何想法可提Issues