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
Craig McNamara 7f335cb032 Allow BUILD_ID to be set using generateBuildId (minor) (#3873)
* Allow BUILD_ID to be set in the environment

This makes multi server deploys with Capistrano possible.

* next.config.js generateBuildId support

enable customising the build id via config

* Provide default for generateBuildId

* This is not used
2018-03-31 16:34:52 +02:00

54 lines
1.3 KiB
JavaScript

// @flow
import findUp from 'find-up'
import uuid from 'uuid'
const cache = new Map()
const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => uuid.v4(),
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)
}