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
1 changed files with 26 additions and 19 deletions

View File

@ -624,33 +624,40 @@ 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()
this.watchers.custom = chokidar
.watch(customPatterns, options)
.on('change', refreshFiles)
const { rewatchOnRawEvents } = this.options.watchers
if (rewatchOnRawEvents && Array.isArray(rewatchOnRawEvents)) {
this.watchers.custom.on('raw', (_event, _path, opts) => {
if (rewatchOnRawEvents.includes(_event)) {
this.watchers.custom.close()
this.watchers.custom = null
watchCustom(true)
}
})
}
if (customPatterns.length === 0) {
return
}
watchCustom()
if (refresh) {
refreshFiles()
}
this.watchers.custom = chokidar
.watch(customPatterns, options)
.on('change', refreshFiles)
const { rewatchOnRawEvents } = this.options.watchers
if (rewatchOnRawEvents && Array.isArray(rewatchOnRawEvents)) {
this.watchers.custom.on('raw', (_event, _path, opts) => {
if (rewatchOnRawEvents.includes(_event)) {
this.watchers.custom.close()
this.watchers.custom = null
this.watchCustom(refreshFiles, true)
}
})
}
}
watchRestart() {