Skip to content
Permalink
Browse files
EnvironmentPlugin: Support empty env variables
  • Loading branch information
eirikurn committed Mar 17, 2017
1 parent 416e5be commit 003cef9625ab4ec804cce7cc49f7b16cd12219a5
@@ -23,7 +23,7 @@ class EnvironmentPlugin {

apply(compiler) {
const definitions = this.keys.reduce((defs, key) => {
const value = process.env[key] || this.defaultValues[key];
const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];

if(value === undefined) {
compiler.plugin("this-compilation", compilation => {
@@ -1,4 +1,4 @@
const variables = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh'];
const variables = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii'];
const modules = [{
name: 'aaa',
variables: ['aaa']
@@ -14,6 +14,9 @@ const modules = [{
}, {
name: 'ggghhh',
variables: ['ggg', 'hhh']
}, {
name: 'iii',
variables: ['iii']
}];

// build an array of regular expressions of expected errors
@@ -28,3 +28,8 @@ it("should import multiple process.env var with default values", () => {
if(process.env.HHH !== "hhh")
require.include("hhh");
});

it("should import process.env var with empty value", () => {
if(process.env.III !== "")
require.include("iii");
});
@@ -6,6 +6,7 @@ process.env.CCC = "ccc";
process.env.EEE = "eee";
process.env.FFF = "fff";
process.env.GGG = "ggg";
process.env.III = "";

module.exports = [{
name: "aaa",
@@ -40,4 +41,10 @@ module.exports = [{
HHH: 'hhh'
})
]
}, {
name: "iii",
module: { unknownContextRegExp: /$^/, unknownContextCritical: false },
plugins: [
new EnvironmentPlugin("III")
]
}];

0 comments on commit 003cef9

Please sign in to comment.