vite-plugin-performance
raw JSON → 2.0.1 verified Mon Apr 27 auth: no javascript
A utility to wrap Vite plugins and measure lifecycle hook execution time, helping identify build performance bottlenecks. Current stable version is 2.0.1, released as part of the weapp-vite monorepo. It supports wrapping single or array of plugins, allows filtering by hook name or threshold, and provides custom logging, formatting, and callback for integration with monitoring systems. Compatible with async hooks. The default hook list covers common Vite plugin hooks like `transform`, `load`, `resolveId`. Differentiators: lightweight, zero-config start, but also flexible for advanced use; includes a built-in default hook list and supports `'all'` to wrap every function hook.
Common errors
error TypeError: plugin.watchChange is not a function ↓
cause wrapPlugin() may be called on a plugin object that does not have the expected hook methods (e.g., array input not flattened correctly).
fix
Ensure you pass either a single plugin object or an array of plugin objects. If passing an array, validate all elements are valid plugins.
error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported ↓
cause Using CommonJS require() to import an ESM-only package.
fix
Use import syntax instead of require(). Set type: module in package.json or rename file to .mjs.
error Module not found: Can't resolve 'vite-plugin-performance' ↓
cause Package not installed or path incorrect.
fix
Run pnpm add -D vite-plugin-performance (or npm/yarn) and ensure the import path matches.
Warnings
breaking vite-plugin-performance is ESM-only starting from v2.0.0. Using require() will throw a Module not found error. ↓
fix Use ESM imports and set type: module in package.json or use .mjs extension.
breaking Node.js version requirement: ^20.19.0 || >=22.12.0. Older versions (e.g., Node 18) are not supported and may cause runtime errors. ↓
fix Upgrade Node to ^20.19.0 or >=22.12.0.
gotcha The `silent` option was previously misspelled as `slient`. In v2.0.0+, `slient` is still supported but deprecated. If both `silent` and `slient` are provided, `silent` takes precedence. ↓
fix Use `silent` instead of `slient` in options.
deprecated The `slient` option (misspelling) will be removed in a future major version. ↓
fix Replace `slient` with `silent`.
Install
npm install vite-plugin-performance yarn add vite-plugin-performance pnpm add vite-plugin-performance Imports
- wrapPlugin wrong
const wrapPlugin = require('vite-plugin-performance')correctimport { wrapPlugin } from 'vite-plugin-performance' - DEFAULT_PLUGIN_HOOKS wrong
import { defaultPluginHooks } from 'vite-plugin-performance'correctimport { DEFAULT_PLUGIN_HOOKS } from 'vite-plugin-performance' - PluginHookName wrong
import { PluginHookName } from 'vite-plugin-performance'correctimport type { PluginHookName } from 'vite-plugin-performance'
Quickstart
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 }) {
console.log(`[${pluginName}] ${hookName} took ${duration}ms`)
},
}),
],
})