mirror of https://github.com/webpack/webpack.git
Merge pull request #4503 from eirikurn/empty-env-variables
EnvironmentPlugin: Support empty env variables
This commit is contained in:
commit
98ea82340f
|
|
@ -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")
|
||||
]
|
||||
}];
|
||||
|
|
|
|||
Loading…
Reference in New Issue