55var DefinePlugin = require ( "./DefinePlugin" ) ;
66
77function EnvironmentPlugin ( keys ) {
8- if ( typeof keys === 'string' ) {
9- throw new Error (
10- "Deprecation notice: EnvironmentPlugin now only takes a single argument."
11- + " Either an array of keys or object with default values."
12- + "\nSee http://webpack.github.io/docs/list-of-plugins.html#environmentplugin for example."
13- ) ;
8+ this . defaultValues = { } ;
9+
10+ if ( Array . isArray ( keys ) ) {
11+ this . keys = keys ;
12+ }
13+
14+ else if ( keys === Object ( keys ) ) {
15+ this . keys = Object . keys ( keys ) ;
16+ this . defaultValues = keys ;
1417 }
1518
16- this . keys = Array . isArray ( keys ) ? keys : Object . keys ( keys ) ;
17- this . defaultValues = Array . isArray ( keys ) ? { } : keys ;
19+ else {
20+ this . keys = Array . prototype . slice . call ( arguments ) ;
21+ }
1822}
1923
2024EnvironmentPlugin . prototype . apply = function ( compiler ) {
21- compiler . apply ( new DefinePlugin ( this . keys . reduce ( function ( definitions , key ) {
25+ var definitions = this . keys . reduce ( function ( defs , key ) {
2226 var value = process . env [ key ] || this . defaultValues [ key ] ;
2327
2428 if ( value === undefined ) {
@@ -29,10 +33,12 @@ EnvironmentPlugin.prototype.apply = function(compiler) {
2933 } ) ;
3034 }
3135
32- definitions [ "process.env." + key ] = value ? JSON . stringify ( value ) : "undefined" ;
36+ defs [ "process.env." + key ] = value ? JSON . stringify ( value ) : "undefined" ;
37+
38+ return defs ;
39+ } . bind ( this ) , { } ) ;
3340
34- return definitions ;
35- } . bind ( this ) , { } ) ) ) ;
41+ compiler . apply ( new DefinePlugin ( definitions ) ) ;
3642} ;
3743
3844module . exports = EnvironmentPlugin ;
0 commit comments