/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Simen Brekken @simenbrekken
*/
var DefinePlugin = require("./DefinePlugin");

function EnvironmentPlugin(keys) {
	this.keys = Array.isArray(keys) ? keys : Array.prototype.slice.call(arguments);
}
module.exports = EnvironmentPlugin;

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

		if(value === undefined) {
			compiler.plugin("this-compilation", function(compilation) {
				var error = new Error(key + " environment variable is undefined.");
				error.name = "EnvVariableNotDefinedError";
				compilation.warnings.push(error);
			});
		}

		definitions["process.env." + key] = value ? JSON.stringify(value) : "undefined";

		return definitions;
	}, {})));
};

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Simen Brekken @simenbrekken
*/
var DefinePlugin = require("./DefinePlugin");

function EnvironmentPlugin(keys, silent) {
	this.keys = Array.isArray(keys) ? keys : Array.prototype.slice.call(arguments);
	this.silent = silent
}
module.exports = EnvironmentPlugin;

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

		if(value === undefined && !this.silent) {
			compiler.plugin("this-compilation", function(compilation) {
				var error = new Error(key + " environment variable is undefined.");
				error.name = "EnvVariableNotDefinedError";
				compilation.warnings.push(error);
			});
		}

		definitions["process.env." + key] = value ? JSON.stringify(value) : "undefined";

		return definitions;
	}.bind(this), {})));
};

Add option to silence warnings from environment plugin
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),
],
```
