A Vite plugin for conditional compilation using comments based on environment variables. Current stable version is 0.4.0. It allows developers to include or exclude code blocks at build time by wrapping them in `#v-ifdef`, `#v-elif`, `#v-else`, and `#v-endif` directives that reference Vite environment variables (e.g., `PROD`, `DEV`, custom env vars). Supports logical OR, custom values, and `!=` comparisons. Since v0.2.0, it wraps `unplugin-preprocessor-directives`. Release cadence is moderate with occasional bug fixes and feature releases. Key differentiator: lightweight, no runtime overhead, and works in any file type (JS, CSS, HTML) via comments.
npm install vite-plugin-conditional-compilerVerified import paths — ran on the pinned version, not inferred.
Setup the plugin in vite.config.ts and use conditional compilation directives in source files.
Update to v0.2.0 or later; no changes required in usage syntax.
Replace `#v-ifndef ENV` with `#v-ifdef !ENV`.
Use multiple `#v-ifdef` blocks or restructure conditionally compiled code to avoid AND logic.
Explicitly set `include` and `exclude` options in plugin configuration to limit processing to relevant files.
Upgrade to v0.1.0+ if you need `!=` comparisons.
Ensure the variable is defined in Vite's `define` or `envPrefix` (default `VITE_`).
Use `#v-ifdef !ENV` instead of `#v-ifndef ENV`.
Run `npm install -D vite-plugin-conditional-compiler` and use correct import (default import).
Ensure directives are exactly `#v-ifdef`, `#v-elif`, `#v-else`, `#v-endif` and environment variables match Vite's (e.g., `PROD`, `DEV`, `VITE_*`).