Skip to content

Commit 7ffa110

Browse files
author
Einar Löve
committed
Add option to silence warnings from environment plugin
If a process.env variable is is added to the EnvironmentPlugin but not defined, it is reported in the terminal as: `WARNING in NODE_ENV environment variable is undefined.` This pull request adds an option as the second argument to EnvironmentPlugin to silence the warnings. Example: ```js plugins: [ new webpack.EnvironmentPlugin([ 'NODE_ENV', ], true), ], ```
1 parent ba93f84 commit 7ffa110

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎lib/EnvironmentPlugin.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
*/
55
var DefinePlugin = require("./DefinePlugin");
66

7-
function EnvironmentPlugin(keys) {
7+
function EnvironmentPlugin(keys, silent) {
88
this.keys = Array.isArray(keys) ? keys : Array.prototype.slice.call(arguments);
9+
this.silent = silent
910
}
1011
module.exports = EnvironmentPlugin;
1112

1213
EnvironmentPlugin.prototype.apply = function(compiler) {
1314
compiler.apply(new DefinePlugin(this.keys.reduce(function(definitions, key) {
1415
var value = process.env[key];
1516

16-
if(value === undefined) {
17+
if(value === undefined && !this.silent) {
1718
compiler.plugin("this-compilation", function(compilation) {
1819
var error = new Error(key + " environment variable is undefined.");
1920
error.name = "EnvVariableNotDefinedError";
@@ -24,5 +25,5 @@ EnvironmentPlugin.prototype.apply = function(compiler) {
2425
definitions["process.env." + key] = value ? JSON.stringify(value) : "undefined";
2526

2627
return definitions;
27-
}, {})));
28+
}.bind(this), {})));
2829
};

0 commit comments

Comments
 (0)