{"id":21114,"library":"decorate-vite-plugin","title":"decorate-vite-plugin","description":"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.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","vite","plugin","hooks","decorate","decorator","typescript"],"install":[{"cmd":"npm install decorate-vite-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add decorate-vite-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add decorate-vite-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export; decoratePlugin decorates a single plugin's hook.","symbol":"decoratePlugin","correct":"import { decoratePlugin } from 'decorate-vite-plugin'"},{"note":"Named export; handles any PluginOption type (array, promise, etc.).","symbol":"decorateVitePluginOption","correct":"import { decorateVitePluginOption } from 'decorate-vite-plugin'"},{"note":"No default export; CJS require will not work. Use named imports only.","wrong":"const decorate = require('decorate-vite-plugin')","symbol":"default export","correct":"import decorate from 'decorate-vite-plugin'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport vue from '@vitejs/plugin-vue';\nimport { decorateVitePluginOption } from 'decorate-vite-plugin';\n\nexport default defineConfig({\n  plugins: [\n    decorateVitePluginOption(\n      vue(),\n      'transform',\n      (originalTransform, plugin) => {\n        return function (code, id) {\n          console.log(`Transforming ${id}`);\n          return originalTransform?.call(plugin, code, id);\n        };\n      },\n    ),\n  ],\n});","lang":"typescript","description":"Decorates the transform hook of @vitejs/plugin-vue with logging."},"warnings":[{"fix":"Always call original hook with plugin context: `originalHook.call(plugin, ...args)`.","message":"The decorator function must preserve the `this` context of the original hook. Use `.call(plugin, ...)` to bind correctly.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Do not rely on reference equality of plugins after decoration.","message":"decorateVitePluginOption may return a different plugin identity, which can affect plugin ordering if compared by reference.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure Vite version is 3 or higher.","message":"Only works with Vite >= v3. Using with older versions will cause runtime errors due to missing Plugin type fields.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use named imports: `import { decoratePlugin } from 'decorate-vite-plugin'`.","message":"The package does not export default; using `import decorate from 'decorate-vite-plugin'` will result in undefined.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Check plugin's available hooks; only existing hooks can be decorated.","cause":"Decorated hook name is not present on the plugin (e.g., plugin has no transform hook).","error":"TypeError: Cannot read properties of undefined (reading 'transform')"},{"fix":"Pass a function as the decorator: `(original, plugin) => { ... }`.","cause":"The decorator argument is not a function.","error":"Error: [vite] The decorator must be a function"},{"fix":"Ensure the hook exists on the plugin; if optional, check for undefined before calling.","cause":"originalTransform is undefined or the hook does not exist.","error":"TypeError: originalTransform.call is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}