@@ -9,39 +9,39 @@ const DefinePlugin = require("./DefinePlugin");
99
1010class EnvironmentPlugin {
1111 constructor ( keys ) {
12- this . defaultValues = { } ;
13-
1412 if ( Array . isArray ( keys ) ) {
1513 this . keys = keys ;
14+ this . defaultValues = { } ;
1615 } else if ( keys && typeof keys === "object" ) {
1716 this . keys = Object . keys ( keys ) ;
1817 this . defaultValues = keys ;
1918 } else {
2019 this . keys = Array . prototype . slice . call ( arguments ) ;
20+ this . defaultValues = { } ;
2121 }
2222 }
2323
2424 apply ( compiler ) {
25- const definitions = this . keys . reduce ( function ( defs , key ) {
25+ const definitions = this . keys . reduce ( ( defs , key ) => {
2626 const value = process . env [ key ] || this . defaultValues [ key ] ;
2727
2828 if ( value === undefined ) {
29- compiler . plugin ( "this-compilation" , function ( compilation ) {
29+ compiler . plugin ( "this-compilation" , compilation => {
3030 const error = new Error (
31- " EnvironmentPlugin - " + key + " environment variable is undefined. \n\n" +
32- " You can pass an object with default values to suppress this warning. \n" +
33- " See https://webpack.js.org/plugins/environment-plugin for example."
31+ ` EnvironmentPlugin - ${ key } environment variable is undefined.\n\n` +
32+ ` You can pass an object with default values to suppress this warning.\n` +
33+ ` See https://webpack.js.org/plugins/environment-plugin for example.`
3434 ) ;
3535
3636 error . name = "EnvVariableNotDefinedError" ;
3737 compilation . warnings . push ( error ) ;
3838 } ) ;
3939 }
4040
41- defs [ " process.env." + key ] = value === undefined ? "undefined" : JSON . stringify ( value ) ;
41+ defs [ ` process.env.${ key } ` ] = value === undefined ? "undefined" : JSON . stringify ( value ) ;
4242
4343 return defs ;
44- } . bind ( this ) , { } ) ;
44+ } , { } ) ;
4545
4646 compiler . apply ( new DefinePlugin ( definitions ) ) ;
4747 }
0 commit comments