Registry / devops / decorate-vite-plugin

decorate-vite-plugin

JSON →
library0.1.0jsnpmunverified

A utility library for decorating Vite plugins by enhancing their hook functions without modifying the original plugin code. Version 0.1.0 supports Vite >= v3. Ships TypeScript types. Key differentiator: provides a non-invasive way to wrap Vite plugin hooks (e.g., transform, resolveId) with custom logic, useful for logging, caching, or modifying behavior. Lightweight with minimal bundle size. Community-maintained with MIT license.

npm install decorate-vite-plugin
INSTALL
IMPORT
SIG · DECORATE-VITE-PLUG
D
decorate-vite-plugin
devopsjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

decoratePlugin
import { decoratePlugin } from 'decorate-vite-plugin'
Named export; decoratePlugin decorates a single plugin's hook.
decorateVitePluginOption
import { decorateVitePluginOption } from 'decorate-vite-plugin'
Named export; handles any PluginOption type (array, promise, etc.).
default export
import decorate from 'decorate-vite-plugin'
const decorate = require('decorate-vite-plugin')
No default export; CJS require will not work. Use named imports only.

Decorates the transform hook of @vitejs/plugin-vue with logging.

import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import { decorateVitePluginOption } from 'decorate-vite-plugin'; export default defineConfig({ plugins: [ decorateVitePluginOption( vue(), 'transform', (originalTransform, plugin) => { return function (code, id) { console.log(`Transforming ${id}`); return originalTransform?.call(plugin, code, id); }; }, ), ], });
Debug
Known issues
gotchaThe decorator function must preserve the `this` context of the original hook. Use `.call(plugin, ...)` to bind correctly.
fix
Always call original hook with plugin context: `originalHook.call(plugin, ...args)`.
affects: >=0.1.0
gotchadecorateVitePluginOption may return a different plugin identity, which can affect plugin ordering if compared by reference.
fix
Do not rely on reference equality of plugins after decoration.
affects: >=0.1.0
gotchaOnly works with Vite >= v3. Using with older versions will cause runtime errors due to missing Plugin type fields.
fix
Ensure Vite version is 3 or higher.
affects: >=0.1.0
gotchaThe package does not export default; using `import decorate from 'decorate-vite-plugin'` will result in undefined.
fix
Use named imports: `import { decoratePlugin } from 'decorate-vite-plugin'`.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'transform')
Decorated hook name is not present on the plugin (e.g., plugin has no transform hook).
fix
Check plugin's available hooks; only existing hooks can be decorated.
Error: [vite] The decorator must be a function
The decorator argument is not a function.
fix
Pass a function as the decorator: `(original, plugin) => { ... }`.
TypeError: originalTransform.call is not a function
originalTransform is undefined or the hook does not exist.
fix
Ensure the hook exists on the plugin; if optional, check for undefined before calling.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
decorate-vite-plugin — npm install decorate-vite-plugin · libregistry