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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vitepress-code-preview/plugin

v1.0.6

Published

preview component of code and component in vitepress

Downloads

192

Readme

🎉 简介

本插件基于 vitepressmarkdown-itunified 实现,它可以帮助你在编写文档的时候,对嵌入的 Vue 示例代码增加演示功能,支持的 Vue 组件形式有 SFC, JSX, TSX

🏄‍♂️ 插件包

| Package | Version | Download | | ------------------------------------------------------- | ----------------------------------------------------------- | --------------------------------------------------------------- | | @vitepress-code-preview/container | npm version | npm downloads | | @vitepress-code-preview/plugin | npm version | npm downloads |

⚙ 安装

pnpm add @vitepress-code-preview/container @vitepress-code-preview/plugin

🚀 引入

  • ① 编辑 docs/vite.config.ts,注册 Vite 插件,如果需要支持 JSX 组件,请安装 @vitejs/plugin-vue-jsx
import { defineConfig } from 'vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { viteDemoPreviewPlugin } from '@vitepress-code-preview/plugin'
export default defineConfig({
  plugins: [viteDemoPreviewPlugin(), vueJsx()],
})
  • ② 编辑 docs/.vitepress/config.ts,注册 markdown 插件
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vitepress'
import { demoPreviewPlugin } from '@vitepress-code-preview/plugin'

export default defineConfig({
  markdown: {
    config(md) {
      const docRoot = fileURLToPath(new URL('../', import.meta.url))
      md.use(demoPreviewPlugin, { docRoot })
    },
  },
})
  • ③ 编辑 docs/.vitepress/theme/index.ts,注册组件容器
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import DemoPreview, { useComponents } from '@vitepress-code-preview/container'
import '@vitepress-code-preview/container/dist/style.css'

export default {
  ...DefaultTheme,
  enhanceApp(ctx) {
    useComponents(ctx.app, DemoPreview)
  },
} satisfies Theme

💡 基础用法

demo容器中直接编写vue代码

:::demo

```vue
<template>
  <div>{{ title }}</div>
</template>
<script lang="ts" setup>
import { ref, defineComponent } from 'vue'
const title = ref('this is basic demo')
</script>
```

:::

basic-demo

💪 支持 JSX 和 TSX

:::demo

```jsx
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const title = ref('this is jsx demo')
    return () => <div>{title.value}</div>
  },
})
```

:::

support-jsx-tsx

✨ 使用其他已注册的组件

假设我们有一个第三方的Button组件已经在.vitepress/theme/index.ts中注册过了,那么就可以在demo容器中使用它

// ...
export default {
  ...DefaultTheme,
  enhanceApp(ctx) {
    // ...
    useComponents(app, Button, Button.name)
  },
} satisfies Theme
:::demo

```vue
<template>
  <MoButton>默认按钮</MoButton>
  <MoButton type="primary">主要按钮</MoButton>
  <MoButton type="success">成功按钮</MoButton>
  <MoButton type="info">信息按钮</MoButton>
  <MoButton type="warning">警告按钮</MoButton>
  <MoButton type="danger">危险按钮</MoButton>
</template>
```

:::

other-component

⚡ 直接引入组件文件

如果你的示例代码比较多,在 markdown 中直接写会比较麻烦,那么可以引入一个单独的组件文件,引入的路径是以docs目录作为根目录

:::demo src=examples/Input.vue
:::

use-file