1- " use strict" ;
1+ ' use strict' ;
22
33const gulpUtil = require ( 'gulp-util' ) ;
4+ const fs = require ( 'fs' ) ;
45const InlineEnviromentVariablesPlugin = require ( 'inline-environment-variables-webpack-plugin' ) ;
56
6- const envFile = './.env' ;
7+ let config = {
8+ silent : false ,
9+ path : './.env'
10+ } ;
711
8- let envEntries = require ( 'dotenv' ) . config ( { silent : true , path : envFile } ) ;
12+ module . exports = {
913
10- if ( Elixir ) {
14+ config : function ( options = { } ) {
15+ config = Object . assign ( config , options ) ;
16+ this . execute ( ) ;
17+ } ,
1118
12- try {
13- const webpack = require ( 'laravel-elixir-webpack-official' ) ;
19+ execute : function ( ) {
20+
21+ if ( Elixir ) {
22+ try {
23+ if ( fs . existsSync ( config . path ) ) {
24+ console . log ( 'found ' + config . path ) ;
25+
26+ const webpack = require ( 'laravel-elixir-webpack-official' ) ;
27+ let envEntries = require ( 'dotenv' ) . config ( config ) ;
28+
29+ Elixir . webpack . mergeConfig ( {
30+ plugins : [
31+ new InlineEnviromentVariablesPlugin ( envEntries )
32+ ]
33+ } ) ;
34+ }
35+ else {
36+ console . log ( config . path + ' not found' ) ;
37+ }
38+ }
39+ catch ( e ) {
40+ gulpUtil . PluginError ( {
41+ plugin : 'laravel-elixir-env' ,
42+ message : 'Currently only webpack is supported.'
43+ } ) ;
44+ }
45+ }
46+ else {
47+ gulpUtil . PluginError ( {
48+ plugin : 'laravel-elixir-env' ,
49+ message : 'Please include laravel-elixir-env after Laravel Elixir.'
50+ } ) ;
51+ }
1452
15- Elixir . webpack . mergeConfig ( {
16- plugins : [
17- new InlineEnviromentVariablesPlugin ( envEntries )
18- ]
19- } ) ;
20- }
21- catch ( e ) {
22- gulpUtil . PluginError ( {
23- plugin : 'laravel-elixir-env' ,
24- message : 'Currently only webpack is supported.'
25- } ) ;
2653 }
2754
28- }
29- else {
30- gulpUtil . PluginError ( {
31- plugin : 'laravel-elixir-env' ,
32- message : 'Please include laravel-elixir-env after Elixir.'
33- } ) ;
34- }
55+ } ;
56+
57+ module . exports . load = module . exports . execute ( ) ;
0 commit comments