Skip to content

Commit

Permalink
EnvironmentPlugin: Support empty env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikurn committed Mar 17, 2017
1 parent 416e5be commit 003cef9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/EnvironmentPlugin.js
Expand Up @@ -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 => {
Expand Down
5 changes: 4 additions & 1 deletion test/configCases/plugins/environment-plugin/errors.js
@@ -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']
Expand All @@ -14,6 +14,9 @@ const modules = [{
}, {
name: 'ggghhh',
variables: ['ggg', 'hhh']
}, {
name: 'iii',
variables: ['iii']
}];

// build an array of regular expressions of expected errors
Expand Down
5 changes: 5 additions & 0 deletions test/configCases/plugins/environment-plugin/index.js
Expand Up @@ -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");
});
7 changes: 7 additions & 0 deletions test/configCases/plugins/environment-plugin/webpack.config.js
Expand Up @@ -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",
Expand Down Expand Up @@ -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.