Improved nuxt dev restart on config change (#2189)

This commit is contained in:
Dmitriy 2017-11-22 00:33:37 +03:00 committed by Pooya Parsa
parent c377a78e7d
commit 4451178c99

View File

@ -69,15 +69,23 @@ _.defaultsDeep(nuxtConfig, { watchers: { chokidar: { ignoreInitial: true } } })
// Start dev // Start dev
let dev = startDev() let dev = startDev()
let needToRestart = false
// Start watching for nuxt.config.js changes // Start watching for nuxt.config.js changes
chokidar chokidar
.watch(nuxtConfigFile, nuxtConfig.watchers.chokidar) .watch(nuxtConfigFile, nuxtConfig.watchers.chokidar)
.on('all', _.debounce(() => { .on('all', () => {
debug('[nuxt.config.js] changed') debug('[nuxt.config.js] changed')
debug('Rebuilding the app...') needToRestart = true
dev = dev.then(startDev)
}), 2500) dev = dev.then((nuxt) => {
if (needToRestart === false) return nuxt
needToRestart = false
debug('Rebuilding the app...')
return startDev(nuxt)
})
})
function startDev(oldNuxt) { function startDev(oldNuxt) {
// Get latest environment variables // Get latest environment variables