A webpack plugin that uses dotenv-safe to load environment variables from a .env file and make them available as process.env replacements during the webpack build. Version 2.1.0 requires webpack >=1.13.0 as a peer dependency. It supports custom paths for .env and sample files, respects externally set environment variables, and fixed a deprecation warning for webpack 4.x. Unlike other dotenv-webpack plugins, this one uses dotenv-safe to ensure required variables are defined. Release cadence is irregular; last update was in 2018.
npm install webpack-dotenv-pluginVerified import paths — ran on the pinned version, not inferred.
Configures webpack to load environment variables from .env file using dotenv-safe, with sample file and allowEmptyValues option.
Rename .env.default to .env.sample or update the sample option to point to your existing file.
Install webpack: npm install --save-dev webpack
Review dotenv-safe 5.0.1 release notes for any deprecated options.
Parse values in your code as needed (e.g., Boolean(process.env.DEBUG)).
Be aware of the override behavior; unset external variables if you want .env to take precedence.
Run: npm install --save-dev webpack-dotenv-plugin
Ensure webpack is installed: npm install --save-dev webpack
Upgrade to webpack-dotenv-plugin >=2.1.0
Create a .env.sample file or specify sample option to point to your existing file.