A secure webpack plugin that wraps dotenv and Webpack.DefinePlugin to expose only explicitly referenced process.env variables in your bundle. Current version 9.0.0 (2026-03-07) supports webpack 4/5 and Node >=18.18.0. Unlike raw dotenv, it safely reduces leakage of sensitive keys by only including variables actually used in code. Compatible with rspack since v8.1.0. Breaking change in v9: package exports directly from src/index.js, no dist/ wrappers. Release cadence is irregular, with major versions every 1-2 years.
npm install dotenv-webpackVerified import paths — ran on the pinned version, not inferred.
Shows basic setup with ESM import, .env file, and secure variable usage.
Update import to default ESM import; if using older Node or custom resolver, ensure module resolution handles src/.
Review config: if you relied on separate defaults, explicitly set options to mimic old behavior.
Always reference variables as process.env.VAR_NAME directly. Do not destructure.
If using `prefix`, ensure all process.env references are handled, or manually handle missing env vars.
Run 'npm install webpack@5 --save-dev' or ensure webpack is in dependencies.
Switch to import syntax or downgrade to v8.1.1 if you cannot use ESM.
Run 'npm install dotenv' or remove --no-optional flag.
Either set `ignoreStub: false` (default) or add 'process/browser' polyfill in webpack config.