1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/config.js

33 lines
652 B
JavaScript
Raw Normal View History

2016-10-28 14:38:24 +00:00
import { join } from 'path'
import { existsSync } from 'fs'
2016-10-28 14:38:24 +00:00
const cache = new Map()
const defaultConfig = {
webpack: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: ''
}
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)
}
function loadConfig (dir) {
const path = join(dir, 'next.config.js')
2016-10-28 14:38:24 +00:00
let userConfig = {}
2016-10-28 14:38:24 +00:00
const userHasConfig = existsSync(path)
if (userHasConfig) {
const userConfigModule = require(path)
userConfig = userConfigModule.default || userConfigModule
}
2016-10-28 14:38:24 +00:00
return Object.assign({}, defaultConfig, userConfig)
2016-10-28 14:38:24 +00:00
}