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

@pzy915/vite-plugin-vitepress-demo

v1.0.0-alpha.31-3

Published

A vite plugin for vitepress code block demo.

Downloads

7

Readme

@pzy915/vite-plugin-vitepress-demo

该项目于2023年1月11日 fork自 vite-plugin-vitepress-demo (版本:2.0.0-alpha.8), 所作的改动为:给AntdTheme组件(对应源代码为src/theme/antd/index.vue)新增了otherSrcArr属性,用于非源码模式下,除了显示src对应文件的源代码外,同时也显示otherSrcArr中指定的对应文件的源代码

对应的 vitepress版本: 1.0.0-alpha.31

一个基于vite的插件,用于vitepress的演示代码块。

banner.png

example.png

如果你现在正在用vuepress,如果你也想实现类似的功能,可以尝试一下vuepress-plugin-code-block

安装

npm i @pzy915/vite-plugin-vitepress-demo -D

插件配置

当前包是一个Pure ESM包,确保当前项目中的package.json中包含"type": "module"

vite.config.[jt]s中做如下配置:

import { defineConfig } from 'vite'
import VitePluginVitepressDemo from '@pzy915/vite-plugin-vitepress-demo'

export default defineConfig({
  plugins: [
    VitePluginVitepressDemo(),
  ],
})

插件属性

  • glob: string | string[]

    指定需要处理的文件,支持glob语法,默认为./**/demos/*.vue

  • base: string

    指定从哪个文件夹进行监听,默认同vite配置的root

  • exclude: string[]

    指定需要排除的文件,支持glob语法,内置:['**/node_modules/**', '**/dist/**', '**/build/**', '**/test/**', '**/tests/**', '**/__tests__/**']默认会排除.vitepress。如果你不想排除.vitepress那么你可以设置exclude:[]

  • markdown: 同vitepress配置的markdown

实验性

目前对于jsx的支持还处于实验阶段,可能会有一些不稳定的地方

组件配置

在2.x版本中,我们支持了自定义组件,但是自定义组件必须和内置组件具有相同的API。

如若我们的自带的主题满足不了你们的需求,那么你可以参考我们的默认主题自定义自己的主题。

同时也欢迎大家提交PR,让我们的主题更加完善。

导入组件

在.vitepress/theme/index.[jt]s中导入组件:

import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { AntdTheme } from 'vite-plugin-vitepress-demo/theme'

export default {
  ...DefaultTheme,
  enhanceApp({ app }) {
    app.component('Demo', AntdTheme)
  },
} as Theme

在markdown中使用

<demo src="./demos/basic.vue" title="标题" desc="描述"></demo>
<demo src="./demos/basic.vue"  :other-src-arr="['./demos/docs.vue']" title="标题" desc="描述"></demo>
<demo src="./demos/basic.vue"  :otherSrcArr="['./demos/docs.vue']" title="标题" desc="描述"></demo>

源码模式

<demo src="./demos/basic.vue" raw></demo>

p.s. 源码模式下不支持otherSrcArr属性,即使配置了也无效

使用描述使用markdown渲染

demos/basic.vue中:

<docs>
---
title: Test Title
---

Hello World This is Test Docs block code in `docs.vue`.

</docs>

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const msg = ref('Hello World')
</script>

markdown中:

<demo src="./demos/docs.vue"></demo>