mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
26c485a22f
* Add X-Powered-By header. * Add support to disable setting x-provided-by header * Add some test cases.
31 lines
613 B
JavaScript
31 lines
613 B
JavaScript
import { join } from 'path'
|
|
import { existsSync } from 'fs'
|
|
|
|
const cache = new Map()
|
|
|
|
const defaultConfig = {
|
|
webpack: null,
|
|
poweredByHeader: true
|
|
}
|
|
|
|
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)
|
|
}
|