Vite plugin that instruments source code with Istanbul/NYC for code coverage, similar to Webpack's istanbul-instrumenter-loader. Current stable version 8.0.0 (released March 2026) supports Vite >=4. Maintained by community with regular releases. Key differentiator: seamless integration with Vite's build pipeline, automatic TypeScript/JSX/Vue support, and optional environment variable gating to avoid instrumenting production builds. Designed for development/test coverage only.
npm install vite-plugin-istanbulVerified import paths — ran on the pinned version, not inferred.
Basic setup: enable Istanbul instrumentation only when VITE_COVERAGE environment variable is set to true, targeting .ts/.vue files in src.
Ensure your Vite version is compatible (>=4). If using Vite 5/6, test instrumentation after upgrade.
Set requireEnv: true explicitly if you want env-gated instrumentation, or set it to false to always instrument.
Use requireEnv: true and set VITE_COVERAGE=false or unset in production CI.
Use `const IstanbulPlugin = require('vite-plugin-istanbul').default` for CJS.If using SSR, consider alternative coverage approaches or test with a separate config.
Run npm install -D @types/babel__generator (or upgrade to v7.2.1+ where it's included).
Use `import IstanbulPlugin from 'vite-plugin-istanbul'` (no curly braces).
Set VITE_COVERAGE=true, or set requireEnv: false, and ensure your file extensions match the extension option.
Use dynamic import: `const IstanbulPlugin = (await import('vite-plugin-istanbul')).default` or configure your project for ESM.