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
2017-05-13 16:44:21 -07:00

34 lines
682 B
JavaScript

import { join } from 'path'
import { existsSync } from 'fs'
const cache = new Map()
const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: ''
}
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')
let userConfig = {}
const userHasConfig = existsSync(path)
if (userHasConfig) {
const userConfigModule = require(path)
userConfig = userConfigModule.default || userConfigModule
}
return Object.assign({}, defaultConfig, userConfig)
}