2016-10-28 14:38:24 +00:00
|
|
|
import { join } from 'path'
|
2016-12-17 18:38:11 +00:00
|
|
|
import { existsSync } from 'fs'
|
2016-10-28 14:38:24 +00:00
|
|
|
|
|
|
|
const cache = new Map()
|
|
|
|
|
2016-12-17 18:38:11 +00:00
|
|
|
const defaultConfig = {
|
2016-12-19 15:27:47 +00:00
|
|
|
webpack: null,
|
2017-04-06 10:09:26 +00:00
|
|
|
poweredByHeader: true,
|
|
|
|
distDir: '.next'
|
2016-12-17 18:38:11 +00:00
|
|
|
}
|
2016-10-28 14:38:24 +00:00
|
|
|
|
|
|
|
export default function getConfig (dir) {
|
|
|
|
if (!cache.has(dir)) {
|
|
|
|
cache.set(dir, loadConfig(dir))
|
|
|
|
}
|
|
|
|
return cache.get(dir)
|
|
|
|
}
|
|
|
|
|
2016-12-17 18:38:11 +00:00
|
|
|
function loadConfig (dir) {
|
|
|
|
const path = join(dir, 'next.config.js')
|
2016-10-28 14:38:24 +00:00
|
|
|
|
2016-12-17 18:38:11 +00:00
|
|
|
let userConfig = {}
|
2016-10-28 14:38:24 +00:00
|
|
|
|
2016-12-17 18:38:11 +00:00
|
|
|
const userHasConfig = existsSync(path)
|
|
|
|
if (userHasConfig) {
|
|
|
|
const userConfigModule = require(path)
|
|
|
|
userConfig = userConfigModule.default || userConfigModule
|
|
|
|
}
|
2016-10-28 14:38:24 +00:00
|
|
|
|
2016-12-17 18:38:11 +00:00
|
|
|
return Object.assign({}, defaultConfig, userConfig)
|
2016-10-28 14:38:24 +00:00
|
|
|
}
|