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-script-preview

v0.0.10

Published

A VitePress plugin for code preview.

Readme

Vitepress Script Preview Plugin

English / 中文

Vitepress Script Preview Plugin 是一个用于 VitePress 的插件,提供了代码预览和运行的功能。通过该插件,用户可以在文档中嵌入代码块,并实时查看代码的输出结果。

功能

  • 支持在 VitePress 文档中嵌入代码块。
  • 实时运行代码并捕获输出(包括 console.logconsole.error 等)。
  • 提供代码复制功能。

安装

在你的项目中安装插件所需的依赖:

npm install vitepress-script-preview

使用方法

  1. 在 VitePress 的配置文件中引入插件:
// docs/.vitepress/config.ts
import { defineConfig } from 'vitepress';
import { codePreviewPlugin } from 'vitepress-script-preview';

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(codePreviewPlugin);
    }
  },
});
  1. 在 VitePress 的主题中注册组件:
// docs/.vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme';
import 'vitepress-script-preview/components/style.css'; // import commonents styles
import { CodePreview } from 'vitepress-script-preview/components';

export default {
  ...DefaultTheme,
  enhanceApp({ app }) {
    app.component('CodePreview', CodePreview);
  }
};
  1. 在文档中使用 script-preview 容器:
::: script-preview

console.log('Hello VitePress!');
console.error('This is an error message.');

:::

示例

以下是一个完整的示例:

# 示例文档

这是一个 VitePress 插件的示例文档。

<script setup>
import { registerContext } from 'vitepress-script-preview/components';

function add(a, b) {
  return a + b;
}

// 脚本内需要调用的函数或变量可以在这里注册
registerContext({
  add
});
</script>

::: script-preview expand=true

console.log(add(1, 2)); // 调用 add 函数
console.info('Hello VitePress!');
console.error('Error example');

:::

expand 参数用于控制输出的展开状态,默认为 false。如果设置为 true,则代码块在加载时会自动展开。

开发

构建组件

npm run build:comp

构建插件

npm run build:plugin

启动文档开发服务器

npm run docs:dev