fix: watch custom patterns only when it exists (#4823)

This commit is contained in:
Xin Du (Clark) 2019-01-21 15:14:17 +00:00 committed by GitHub
parent fe57a5a929
commit 3966b265f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -624,14 +624,24 @@ export default class Builder {
.on('add', refreshFiles)
.on('unlink', refreshFiles)
this.watchCustom(refreshFiles)
}
watchCustom(refreshFiles, refresh) {
const options = this.options.watchers.chokidar
// Watch for custom provided files
const customPatterns = uniq([
...this.options.build.watch,
...Object.values(omit(this.options.build.styleResources, ['options']))
]).map(upath.normalizeSafe)
const watchCustom = (refresh) => {
if (refresh) refreshFiles()
if (customPatterns.length === 0) {
return
}
if (refresh) {
refreshFiles()
}
this.watchers.custom = chokidar
.watch(customPatterns, options)
@ -644,15 +654,12 @@ export default class Builder {
this.watchers.custom.close()
this.watchers.custom = null
watchCustom(true)
this.watchCustom(refreshFiles, true)
}
})
}
}
watchCustom()
}
watchRestart() {
const nuxtRestartWatch = [
// Server middleware