node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



A plugin that extends DefinePlugin to help load configuration based on environment.


First, install with npm:

npm install webpack-env-loader-plugin --save

Add an instance of the plugin to webpack.config.js:

const EnvLoaderPlugin = require("webpack-env-loader-plugin");
module.exports = {
  plugins: [
    new EnvLoaderPlugin(options)

How it works

EnvLoaderPlugin will pick up configuration from files with the pattern config.{env}.json, or a custom pattern you define, in this order:

  1. First, it will look for config.default.json (or config.default.yml, if you're into that)
  2. Next, it will look for config.{env}.json, where {env} is process.env.NODE_ENV

In your javascript files processed by webpack, all configuration values are exposed under a global object (__CONFIG__ by default):

if (__CONFIG__.FOO) {

If you want to trigger webpack builds with different environments, just make sure you set NODE_ENV:

NODE_ENV=production webpack



Default: process.env.NODE_ENV

You can use this option to override process.env.NODE_ENV if you want to specify it explicitly.


Default: false

Add configuration that will set React to production mode if env is "production".


Default: process.cwd()

This is the path in which to look for config files.


Default: config.{env}.json

Pattern to file config files. {env} is replaced by whatever env is.


Default: "CONFIG"

Object that prefixes your config variables, so they don't pollute global state. If you are using eslint, make sure you add it to globals.


Default: true

Load config.default.json (or whatever your filePattern is with {env} set to default) before loading other configuration files.


Default: null

If you specify a path in this option, the plugin will load the file and override all other configuration EXCEPT process.env;

loadFromProcessEnv (TODO, not yet implemented)

Default: true

Override configuration with values from process.env if they are found.


Default: true

Log progress to console.