Registry / testing / esbuild-plugin-vitest-cleaner

esbuild-plugin-vitest-cleaner

JSON →
library0.5.1jsnpmunverified

An esbuild plugin that removes import.meta.vitest references and associated code blocks before compilation, preventing test code from leaking into production builds. Current stable version is 0.5.1, with no fixed release cadence. Key differentiator: lightweight alternative to esbuild's built-in drop feature or conditional compilation, with support for file filtering via regex. Ships TypeScript type definitions. Requires Node >= 18.0.0. Known issue: JSDoc comments around import.meta.vitest are not stripped.

testingdevops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

Package exports ESM only; CommonJS require() will fail.

import { vitestCleaner } from 'esbuild-plugin-vitest-cleaner'

Named export, not default export.

import { vitestCleaner } from 'esbuild-plugin-vitest-cleaner'

Type import only for TypeScript users; not a runtime export.

import type { FilterOptions } from 'esbuild-plugin-vitest-cleaner'

Demonstrates basic usage with esbuild build, stripping import.meta.vitest from the output.

import { build } from 'esbuild'; import { vitestCleaner } from 'esbuild-plugin-vitest-cleaner'; await build({ entryPoints: ['src/index.ts'], outfile: 'dist/index.js', bundle: true, plugins: [vitestCleaner()] });
Debug
Known footguns
gotchaJSDoc comments that annotate import.meta.vitest evaluations are not removed; leftover comments may contain test references.
gotchaPlugin uses regex-based removal; complex code blocks with nested import.meta.vitest may not be fully stripped.
breakingOnly supports ESM; Node CJS require() will throw a module import error.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
ahrefsbot
4
claudebot
4
gptbot
3
bingbot
1
Resources