import { join } from 'path' import { existsSync } from 'fs' const cache = new Map() const defaultConfig = { webpack: 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) }