@@ -3,41 +3,25 @@ const { safeLoad } = require('js-yaml')
3
3
const { readFileSync } = require ( 'fs' )
4
4
const deepMerge = require ( './utils/deep_merge' )
5
5
const { isArray } = require ( './utils/helpers' )
6
+ const env = require ( './env' )
6
7
7
- const defaultFilePath = require . resolve ( '../lib/install/config/webpacker.yml' )
8
- const filePath = resolve ( 'config' , 'webpacker.yml' )
8
+ const defaultConfigPath = require . resolve ( '../lib/install/config/webpacker.yml' )
9
+ const configPath = resolve ( 'config' , 'webpacker.yml' )
9
10
10
- const environment = process . env . NODE_ENV || 'development'
11
- const defaultConfig = safeLoad ( readFileSync ( defaultFilePath ) , 'utf8' ) [ environment ]
12
- const appConfig = safeLoad ( readFileSync ( filePath ) , 'utf8' ) [ environment ]
11
+ const getConfig = ( ) => {
12
+ const defaults = safeLoad ( readFileSync ( defaultConfigPath ) , 'utf8' ) [ env ]
13
+ const app = safeLoad ( readFileSync ( configPath ) , 'utf8' ) [ env ]
13
14
14
- if ( isArray ( appConfig . extensions ) && appConfig . extensions . length ) {
15
- delete defaultConfig . extensions
16
- } else {
17
- /* eslint no-console: 0 */
18
- console . warn ( 'No extensions specified in webpacker.yml, using default extensions\n' )
19
- }
20
-
21
- const config = deepMerge ( defaultConfig , appConfig )
15
+ if ( isArray ( app . extensions ) && app . extensions . length ) {
16
+ delete defaults . extensions
17
+ }
22
18
23
- const isBoolean = str => / ^ t r u e / . test ( str ) || / ^ f a l s e / . test ( str )
19
+ const config = deepMerge ( defaults , app )
24
20
25
- const fetch = key =>
26
- ( isBoolean ( process . env [ key ] ) ? JSON . parse ( process . env [ key ] ) : process . env [ key ] )
21
+ config . outputPath = resolve ( 'public' , config . public_output_path )
22
+ config . publicPath = `/ ${ config . public_output_path } /` . replace ( / ( [ ^ : ] \/ ) \/ + / g , '$1' )
27
23
28
- const devServer = ( key ) => {
29
- const envValue = fetch ( `WEBPACKER_DEV_SERVER_${ key . toUpperCase ( ) . replace ( / _ / g, '' ) } ` )
30
- if ( typeof envValue === 'undefined' || envValue === null ) return config . dev_server [ key ]
31
- return envValue
24
+ return config
32
25
}
33
26
34
- if ( config . dev_server ) {
35
- Object . keys ( config . dev_server ) . forEach ( ( key ) => {
36
- config . dev_server [ key ] = devServer ( key )
37
- } )
38
- }
39
-
40
- config . outputPath = resolve ( 'public' , config . public_output_path )
41
- config . publicPath = `/${ config . public_output_path } /` . replace ( / ( [ ^ : ] \/ ) \/ + / g, '$1' )
42
-
43
- module . exports = config
27
+ module . exports = getConfig ( )
0 commit comments