Registry / devops / esbuild-plugin-auto-env

esbuild-plugin-auto-env

JSON →
library0.3.0jsnpmunverified

An esbuild plugin that automatically replaces environment variable references in source code with values defined at build time. Current stable version is 0.3.0, released September 2023. Update cadence is irregular. Key differentiators: supports glob-based include/exclude patterns for fine-grained control, allows ignoring specific environment variables, and replaces with undefined in browser mode. Alternative to manual Define or envsubst approaches. Ships TypeScript types.

devops
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 is ESM-only; CJS require() will not work. Use import syntax.

import { autoEnv } from 'esbuild-plugin-auto-env'

Package does not export a default export. Must use named import.

import autoEnv from 'esbuild-plugin-auto-env'

Shows basic usage of autoEnv plugin with esbuild, replacing environment variables in src directory with build-time values.

import esbuild from 'esbuild'; import { autoEnv } from 'esbuild-plugin-auto-env'; await esbuild.build({ entryPoints: ['src/index.js'], outfile: 'dist/index.js', bundle: true, plugins: [autoEnv()], });
Debug
Known footguns
breakingWhen using `browser` platform, undefined environment variables are replaced with the string `undefined` (not `undefined` value), which may cause bugs.
breakingIn v0.3.0, include and exclude now support glob patterns using node-glob syntax; previous versions used simple strings. This changes behavior for patterns like `src/**/*.js`.
deprecatedThe `cwd` option was removed in v0.2.0; use esbuild's `absWorkingDir` option instead.
gotchaEnvironment variables are only replaced if they appear as `process.env.VAR_NAME`. Other patterns (e.g., `process.env['VAR_NAME']` or destructured variables) are not replaced.
gotchaThe default `include` pattern includes only files under `src/`. If your source files are elsewhere, they will not be scanned for env vars.
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
10 hits · last 30 days
ahrefsbot
4
gptbot
3
claudebot
3
Resources