mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 23:21:09 +00:00
fix: watch custom patterns only when it exists (#4823)
This commit is contained in:
parent
fe57a5a929
commit
3966b265f9
@ -624,33 +624,40 @@ export default class Builder {
|
|||||||
.on('add', refreshFiles)
|
.on('add', refreshFiles)
|
||||||
.on('unlink', refreshFiles)
|
.on('unlink', refreshFiles)
|
||||||
|
|
||||||
|
this.watchCustom(refreshFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
watchCustom(refreshFiles, refresh) {
|
||||||
|
const options = this.options.watchers.chokidar
|
||||||
// Watch for custom provided files
|
// Watch for custom provided files
|
||||||
const customPatterns = uniq([
|
const customPatterns = uniq([
|
||||||
...this.options.build.watch,
|
...this.options.build.watch,
|
||||||
...Object.values(omit(this.options.build.styleResources, ['options']))
|
...Object.values(omit(this.options.build.styleResources, ['options']))
|
||||||
]).map(upath.normalizeSafe)
|
]).map(upath.normalizeSafe)
|
||||||
|
|
||||||
const watchCustom = (refresh) => {
|
if (customPatterns.length === 0) {
|
||||||
if (refresh) refreshFiles()
|
return
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
watchRestart() {
|
||||||
|
Loading…
Reference in New Issue
Block a user