@marcuwynu23/vite-plugin-env-banner
v1.0.0
Published
A Vite plugin that shows a floating environment badge to help developers identify the current app environment.
Downloads
129
Maintainers
Readme
The banner is intentionally disabled when the resolved environment is production.
Why use this plugin
- Reduce deployment mistakes by making environment context obvious.
- Keep QA/UAT demos clear with visible
DEVELOPMENT/STAGINGlabels. - Move the badge anywhere on screen when it overlaps UI controls.
- Use zero runtime dependencies.
Features
- Uses Vite's
transformIndexHtmlto inject the banner. - Draggable banner implemented with vanilla JavaScript.
- Built-in color mapping:
development-> bluestaging-> orange- any other non-production value -> gray
- Defaults to
developmentwhen no value is resolved. - Skips injection entirely for
production. - Supports explicit env source via
envorenvfile.
Installation
npm install @marcuwynu23/vite-plugin-env-bannerQuick Start
import {defineConfig} from "vite";
import envBanner from "@marcuwynu23/vite-plugin-env-banner";
export default defineConfig({
plugins: [envBanner()],
});JavaScript config is also supported:
import {defineConfig} from "vite";
import envBanner from "@marcuwynu23/vite-plugin-env-banner";
export default defineConfig({
plugins: [envBanner()],
});Configuration
envBanner({
env: "staging",
envfile: "./config/.env.staging",
});Options
| Option | Type | Required | Description |
| --------- | -------- | -------- | ----------------------------------------------------------------------------------------------- |
| env | string | No | Hard override for the environment value (production, staging, etc.). |
| envfile | string | No | Path to a specific env file to read VITE_APP_ENV from. Relative paths resolve from Vite root. |
Resolution precedence
The plugin resolves the final environment in this order:
envoptionenvfilevalue (VITE_APP_ENVkey inside that file)- Vite resolved env (
VITE_APP_ENV) - fallback:
development
Environment Example
.env:
VITE_APP_ENV=developmentWhen VITE_APP_ENV=production, the plugin returns HTML unchanged and injects nothing.
Example Project
A runnable Vite + React sample is included in example-react.
cd example-react
npm install
npm run devLicense
MIT
