mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
e90f89633c
* Initial implementation of next export without exportPathMap * Shorter message * Set up flow * Create pages manifest * Use pagesManifest for next export * Fix tests * Document defaultPathMap * Replacing the path is no longer needed * Use posix normalize for consistent behaviour * Remove second instance of examples * Add comment about what pages-manifest does * Make windows path a route
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
// @flow
|
|
import findUp from 'find-up'
|
|
|
|
const cache = new Map()
|
|
|
|
const defaultConfig = {
|
|
webpack: null,
|
|
webpackDevMiddleware: null,
|
|
poweredByHeader: true,
|
|
distDir: '.next',
|
|
assetPrefix: '',
|
|
configOrigin: 'default',
|
|
useFileSystemPublicRoutes: true,
|
|
generateEtags: true,
|
|
pageExtensions: ['jsx', 'js']
|
|
}
|
|
|
|
export default function getConfig (phase: string, dir: string, customConfig?: ?Object) {
|
|
if (!cache.has(dir)) {
|
|
cache.set(dir, loadConfig(phase, dir, customConfig))
|
|
}
|
|
return cache.get(dir)
|
|
}
|
|
|
|
export function loadConfig (phase: string, dir: string, customConfig?: ?Object) {
|
|
if (customConfig && typeof customConfig === 'object') {
|
|
customConfig.configOrigin = 'server'
|
|
return withDefaults(customConfig)
|
|
}
|
|
const path: string = findUp.sync('next.config.js', {
|
|
cwd: dir
|
|
})
|
|
|
|
let userConfig = {}
|
|
|
|
if (path && path.length) {
|
|
// $FlowFixMe
|
|
const userConfigModule = require(path)
|
|
userConfig = userConfigModule.default || userConfigModule
|
|
if (typeof userConfigModule === 'function') {
|
|
userConfig = userConfigModule(phase, {defaultConfig})
|
|
}
|
|
userConfig.configOrigin = 'next.config.js'
|
|
}
|
|
|
|
return withDefaults(userConfig)
|
|
}
|
|
|
|
function withDefaults (config: Object) {
|
|
return Object.assign({}, defaultConfig, config)
|
|
}
|