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

vitepress-plugin-component

v1.1.1

Published

VitePress plugin that renders Vue components with tabs showing preview and source code

Downloads

66

Readme

Vitepress Plugin Component

简体中文

A VitePress plugin to display Vue components in your documentation with an automatically generated two-tab interface: one for the component's preview and another to show its source code.

Features

  • [x] Component Preview - Directly view the rendered output of your component within the documentation.
  • [x] Syntax Highlighting - Compatible with VitePress's syntax highlighting.
  • [ ] Code Copying - One-click copy for the component's source code.
  • [x] Dark Mode Support - Automatically adapts to VitePress's light and dark themes.
  • [x] Lightweight - No complex dependencies, only 2kb / gzip:1kb.
  • [x] Internationalization Support - Default support for Chinese and English, configurable for other languages.

Installation

npm install vitepress-plugin-component --save-dev

Configuration

Add Markdown Plugin

Add the plugin to your VitePress configuration file (.vitepress/config.js or .vitepress/config.ts):

import { defineConfig } from 'vitepress'
import { componentViewMarkdownPlugin } from 'vitepress-plugin-component'

export default defineConfig({
  // ... other configurations

  markdown: {
    config: (md) => {
      md.use(componentViewMarkdownPlugin)
    }
  },
})

Configure Client

VitePress resolves themes from .vitepress/theme/index.js or .vitepress/theme/index.ts, and we configure the client here as well.

// theme/index.ts
import DefaultTheme from "vitepress/theme";
import { enhanceAppWithComponentView } from 'vitepress-plugin-component/client'

export default {
  extends: DefaultTheme, // Use VitePress's default theme
  enhanceApp({ app }) {
    enhanceAppWithComponentView(app)
  }
}

The enhanceAppWithComponentView function automatically registers the preview component on the passed root component.

Configure Internationalization

The plugin gets language configuration from the locales.lang option in VitePress and supports zh and en languages by default. You can also manually configure other languages or even override the default languages.

Configure internationalization in the client configuration:

export default {
  // Other configurations
  enhanceApp({ app }) {
    enhanceAppWithComponentView(app, {
      // Configure corresponding languages through localeMappings option
      localeMappings: {
        fr: {
          previewLabel: "foo",
          codeLabel: "bar",
        },
      },
    });
  },
};

Example

This is an example of button SFC:

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

const count = ref(0)
</script>

<template>
  <button class="my-button" @click="count++">
    Clicked {{ count }} times
  </button>
</template>

<style>
.my-button {
  background-color: #3eaf7c;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
</style>

VitePress supports importing Vue components in markdown files, we import the Button component in the same way:

<script setup>
import Button from './Button.vue'
</script>

Then use the specified syntax:

::: component-view
<Button />
:::

Here is the complete example code in a markdown file:

<script setup>
import Button from './Button.vue'
</script>

# This will render a button with click count and a tab bar showing **Preview** and **Source Code**

::: component-view
<Button />
:::

##

You can view the component's preview and source code in the tabs above.

You can check out the live demo here.

Notes

  • Component paths should be relative to the project root.
  • Current version supports simple Vue components; complex components might require additional configuration. - Components must be valid Single File Components (SFCs).

License

MIT