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

39 lines
1 KiB
JavaScript
Raw Normal View History

import findUp from 'find-up'
2018-10-01 22:55:31 +00:00
import {CONFIG_FILE} from 'next-server/constants'
const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => null,
generateEtags: true,
pageExtensions: ['jsx', 'js']
}
2016-10-28 14:38:24 +00:00
export default function loadConfig (phase, dir, customConfig) {
if (customConfig) {
customConfig.configOrigin = 'server'
return {...defaultConfig, ...customConfig}
}
const path = findUp.sync(CONFIG_FILE, {
cwd: dir
})
2016-10-28 14:38:24 +00:00
// If config file was found
if (path && path.length) {
const userConfigModule = require(path)
const userConfigInitial = userConfigModule.default || userConfigModule
if (typeof userConfigInitial === 'function') {
return {...defaultConfig, configOrigin: CONFIG_FILE, ...userConfigInitial(phase, {defaultConfig})}
}
2016-10-28 14:38:24 +00:00
return {...defaultConfig, configOrigin: CONFIG_FILE, ...userConfigInitial}
}
return defaultConfig
2016-10-28 14:38:24 +00:00
}