An esbuild plugin that automatically loads environment variables from a .env file (found in the current directory or any parent) and merges them with existing process.env variables. The .env variables are made available to the bundled code via ESM imports from the virtual module 'env'. This plugin version 1.0.7 is stable and leverages the dotenv package for parsing (not added to user's project). It differentiates by providing a simple, zero-config solution for esbuild bundling, unlike the more general dotenv or @rollup/plugin-dotenv which require explicit setup. Installation requires esbuild and dotenv as dev dependencies.
npm install esbuild-envfile-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows installation, esbuild configuration with the plugin, and usage of environment variables from the virtual 'env' module.
Ensure all files importing 'env' are included in the esbuild build entry points.
Run 'npm install dotenv --save-dev' in your project.
To force override, set the variable in process.env before calling esbuild, or modify the .env file.
Set esbuild platform to 'node' or omit platform setting (defaults to browser).
Run 'npm install esbuild-envfile-plugin --save-dev' and ensure require path is correct.
Only import 'env' in files that are processed by esbuild with the plugin installed.
Make sure you pass the plugin in the plugins array: plugins: [envFilePlugin].
Run 'npm install dotenv --save-dev'.