@@ -9,18 +9,24 @@ import { parsePlugins } from './plugins'
9
9
10
10
const exists = promisify ( fs . exists )
11
11
12
- export async function getConfig ( { dev } ) {
13
- const configPath = 'smooth.config.js'
14
- const localCwd = cwd ( )
15
- const absConfigPath = path . resolve ( localCwd , configPath )
16
- const configExists = await exists ( absConfigPath )
12
+ async function mergeLocalConfig ( configPath , defaultConfig ) {
13
+ const configExists = await exists ( configPath )
17
14
18
15
if ( ! configExists ) {
19
- throw new Error ( `Error: config not found " ${ configPath } "` )
16
+ return defaultConfig
20
17
}
21
18
22
19
// eslint-disable-next-line global-require, import/no-dynamic-require
23
- const getLocalConfig = babelRequire ( absConfigPath )
20
+ const localConfig = babelRequire ( configPath )
21
+ const config = merge ( defaultConfig , localConfig )
22
+ if ( localConfig . webpack ) config . webpack = localConfig . webpack
23
+ if ( localConfig . webpackDevMiddleware )
24
+ config . webpackDevMiddleware = localConfig . webpackDevMiddleware
25
+ return config
26
+ }
27
+
28
+ export async function getConfig ( { dev } ) {
29
+ const localCwd = cwd ( )
24
30
25
31
const defaultConfig = {
26
32
env : process . env . NODE_ENV || 'development' ,
@@ -41,8 +47,11 @@ export async function getConfig({ dev }) {
41
47
webpackDevMiddleware : x => x ,
42
48
}
43
49
44
- const localConfig = getLocalConfig
45
- const config = merge ( { } , defaultConfig , localConfig )
50
+ const config = await mergeLocalConfig (
51
+ path . resolve ( localCwd , 'smooth.config.js' ) ,
52
+ defaultConfig ,
53
+ )
54
+
46
55
config . webpackConfig = await getWebpackConfig ( { config, dev } )
47
56
config . plugins = parsePlugins ( config . plugins )
48
57
return config
0 commit comments