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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@movk-repo/demo-preview

v1.1.0

Published

vitepress 插件,用于预览 markdown 文件

Readme

组件预览与展示代码 {#start}

专为增强 Markdown 文档设计,特别适用于 VueTSX 组件的实时预览与代码展示,支持自定义容器及 SSR 兼容。

在线示例

更新日志

✨ 特点 {#features}

  • 自定义容器:支持灵活配置容器符号和名称,满足不同文档结构的需求。
  • 样式隔离机制:提供 vp-raw 类名控制隔离区域,确保示例组件样式不受影响。
  • 组件支持:兼容 .vue.tsx 组件,轻松引入多种前端框架示例。
  • 可修改根目录:支持自定义根目录(默认 /examples),便于项目示例文件的组织和管理。
  • 简化路径管理:通过相对路径直接引入示例文件,如 /demo/test.tsx,简化路径配置。
  • SSR 兼容性:轻松使用 {ClientOnly} 选项,灵活控制组件加载方式,增强服务端渲染兼容性。
  • VitePress 扩展支持:完美支持 VitePress 的 行内语法高亮代码行号代码组 功能,提升文档的可读性和交互性。
  • 高效渲染:基于 VitePress 默认的服务端渲染机制,确保示例演示内容快速加载,提升用户体验和搜索引擎优化(SEO)。
  • 暗黑模式兼容:原生支持暗黑模式,为用户提供更好的视觉体验。

📦 安装 {#install}

::: code-group

pnpm add @movk-repo/demo-preview
npm add @movk-repo/demo-preview
yarn add @movk-repo/demo-preview

:::

🚀 使用 {#usage}

添加插件 {#plugin}

.vitepress/config.ts 中添加插件

import { demoPreviewPlugin } from '@movk-repo/demo-preview' // [!code ++]
import { defineConfig } from 'vitepress'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(demoPreviewPlugin) // [!code ++]
    },
  },
})

注册容器组件 {#container}

.vitepress/theme/index.ts 中注册容器组件

import type { Theme } from 'vitepress'
import { DemoPreviewContainer } from '@movk-repo/demo-preview/container' // [!code ++]
import DefaultTheme from 'vitepress/theme'
import '@movk-repo/demo-preview/style.css' // [!code ++]

export default {
  extends: DefaultTheme,
  enhanceApp({ app }) {
    // 注册自定义全局组件
    app.component('DemoPreview', DemoPreviewContainer) // [!code ++]
  },
} satisfies Theme

添加样式隔离 {#vp-raw}

配置详情参考 vitepress 自定义容器

import { postcssIsolateStyles } from 'vitepress'

export default {
  plugins: [
    postcssIsolateStyles({
      includeFiles: [/base\.css/, /vp-doc\.css/],
    })
  ]
}

🛠️ 配置 {#config}

root

  • 类型: string
  • 默认值: join(process.cwd(), 'examples')

示例文件所在的根目录,默认值为 /examples,文件目录结构如下:

.
├─ docs
│  ├─ .vitepress
│  │  ├─ theme
│  │  │  └─ index.ts
│  │  └─ config.ts
│  └─ index.md
├─ examples
│  ├─ test.tsx
│  └─ test.vue
└─ package.json

::: tip 提示

如果需要修改根目录,请确保在 .vitepress/config.ts 中配置 root 选项。

import { resolve } from 'node:path' // [!code ++]
import { demoPreviewPlugin } from '@movk-repo/demo-preview' // [!code ++]
import { defineConfig } from 'vitepress'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(demoPreviewPlugin, {
        root: resolve('./docs') // [!code ++]
      })
    },
  },
})

:::

marker

  • 类型: string
  • 默认值: ':'

容器标记符号,用于标识容器的开始和结束。

name

  • 类型: string
  • 默认值: demo

自定义容器名称,用于标识容器的类型。