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

vite-plugin-performance

v1.0.0

Published

vite-plugin-performance

Downloads

477

Readme

vite-plugin-performance

English Documentation

一个用于包裹 Vite 插件、统计生命周期钩子耗时的小工具,帮助你快速定位构建链路中的性能瓶颈。插件原有行为保持不变,我们只在钩子执行完成后采集数据并按需输出或上报。

✨ 特性

  • 支持同时包裹单个插件或插件数组
  • 内置常用钩子列表,可设置 hooks: 'all' 包裹所有函数钩子
  • 阈值过滤机制,只关注真正慢的钩子
  • 自定义日志、格式化与回调,方便接入监控体系
  • 兼容异步钩子,异常也会统计耗时

📦 安装

pnpm add -D vite-plugin-performance
# 或 npm / yarn / bun

🚀 快速上手

import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import { wrapPlugin } from 'vite-plugin-performance'

export default defineConfig({
  plugins: [
    wrapPlugin(Inspect(), {
      threshold: 50,
      onHookExecution({ pluginName, hookName, duration }) {
        reportToAPM({ pluginName, hookName, duration })
      },
    }),
  ],
})

当某个钩子耗时超过设置的阈值(默认 0 ms)时,控制台会输出:

[inspect] transform            ⏱   78.42 ms

⚙️ 选项

| 选项 | 类型 | 默认值 | 说明 | | ----------------- | ---------------------------- | --------------------------------- | --------------------------------------------- | | hooks | PluginHookName[] \| 'all' | DEFAULT_PLUGIN_HOOKS | 指定需要包裹的钩子;传 all 包裹所有函数钩子 | | threshold | number | 0 | 只有耗时大于等于该值的钩子才会被记录 | | silent | boolean | false | 关闭内置日志输出 | | logger | (message, context) => void | console.log | 自定义日志输出函数 | | formatter | (context) => string | [plugin] transform ⏱ 12.34 ms | 自定义日志内容格式 | | onHookExecution | (context) => void | undefined | 钩子执行完毕后触发,可用于上报 | | clock | () => number | performance.nowDate.now | 高精度计时器,便于测试或自定义时间源 |

兼容早期误拼写的 slient 选项,会自动映射为 silent

默认钩子列表

import { DEFAULT_PLUGIN_HOOKS } from 'vite-plugin-performance'
// [
//   'options',
//   'config',
//   'configResolved',
//   'configureServer',
//   'buildStart',
//   'resolveId',
//   'load',
//   'transform',
//   'buildEnd',
//   'generateBundle',
//   'renderChunk',
//   'writeBundle',
// ]

🧠 进阶用法

包裹多个插件

const pluginA = ...
const pluginB = ...

export default defineConfig({
  plugins: wrapPlugin([pluginA, pluginB], { threshold: 20 }),
})

自定义日志格式

wrapPlugin(plugin, {
  formatter({ pluginName, hookName, duration }) {
    return `${pluginName}:${hookName} took ${duration}ms`
  },
  logger(message) {
    myLogger.info(message)
  },
})

仅关注特定钩子

wrapPlugin(plugin, {
  hooks: ['resolveId', 'load', 'transform'],
})

🧪 测试

pnpm --filter vite-plugin-performance test

📄 许可

MIT