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
Ives van Hoorne 5ab7463b93 Exploration of different config + expose webpack config (#222)
* 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
2016-12-17 10:38:11 -08:00

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)
}