fix(cli): watch and reload nuxt.config (#5574)

[release]
This commit is contained in:
Pooya Parsa 2019-04-21 15:39:26 +04:30 committed by GitHub
parent 5c4e8f6983
commit c9a95429eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,11 +21,13 @@ export async function loadNuxtConfig(argv) {
}
if (nuxtConfigFile) {
// Clear cache
clearRequireCache(nuxtConfigFile)
if (nuxtConfigFile.endsWith('.ts')) {
options = require(nuxtConfigFile) || {}
} else {
clearRequireCache(nuxtConfigFile)
options = esm(module, { cache: false, cjs: { cache: false } })(nuxtConfigFile) || {}
options = esm(module, { cache: false, cjs: { cache: true } })(nuxtConfigFile) || {}
}
if (options.default) {
@ -49,6 +51,9 @@ export async function loadNuxtConfig(argv) {
// Keep all related files for watching
options._nuxtConfigFiles = Array.from(scanRequireTree(nuxtConfigFile))
if (!options._nuxtConfigFiles.includes(nuxtConfigFile)) {
options._nuxtConfigFiles.unshift(nuxtConfigFile)
}
}
if (typeof options.rootDir !== 'string') {