mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
![Ives van Hoorne](/assets/img/avatar_default.png)
* Use next.config.js instead of package.json * Remove irrelevant comment * Integrate with custom webpack config * Include hotReload option * Remove async/await for getConfig * Read package.json, show warning when webpack in config is defined * Prepend warning message with WARNING * Update log statements * Documentation * Restart server on change of config * Fix process handling and cases where there is no config * Also restart server when config file gets deleted * Changed second parameter of webpack to config * Support for returning Promise * Update documentation, fix bug with webpack config * Remove package.json, cdn and hotReload from config
30 lines
588 B
JavaScript
30 lines
588 B
JavaScript
import { join } from 'path'
|
|
import { existsSync } from 'fs'
|
|
|
|
const cache = new Map()
|
|
|
|
const defaultConfig = {
|
|
webpack: null
|
|
}
|
|
|
|
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)
|
|
}
|