diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 0e20c421bd..4992870b96 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -35,9 +35,11 @@ export default class Builder { this.compilersWatching = [] this.webpackDevMiddleware = null this.webpackHotMiddleware = null - this.filesWatcher = null - this.customFilesWatcher = null - this.nuxtRestartWatcher = null + this.watchers = { + files: null, + custom: null, + restart: null + } this.perfLoader = null // Helper to resolve build paths @@ -610,7 +612,7 @@ export default class Builder { const refreshFiles = _.debounce(() => this.generateRoutesAndFiles(), 200) // Watch for src Files - this.filesWatcher = chokidar + this.watchers.files = chokidar .watch(patterns, options) .on('add', refreshFiles) .on('unlink', refreshFiles) @@ -621,7 +623,7 @@ export default class Builder { ..._.values(_.omit(this.options.build.styleResources, ['options'])) ) customPatterns = _.map(_.uniq(customPatterns), upath.normalizeSafe) - this.customFilesWatcher = chokidar + this.watchers.custom = chokidar .watch(customPatterns, options) .on('change', refreshFiles) @@ -631,10 +633,10 @@ export default class Builder { }) const nuxtRestartWatch = _.concat( - this.options.watch, + this.options.watch.map(r), path.join(this.options.rootDir, 'nuxt.config.js') ) - this.nuxtRestartWatcher = chokidar + this.watchers.restart = chokidar .watch(nuxtRestartWatch, options) .on('change', (event, _path) => { const parsedPath = path.parse(_path) @@ -643,16 +645,10 @@ export default class Builder { } async unwatch() { - if (this.filesWatcher) { - this.filesWatcher.close() - } - - if (this.customFilesWatcher) { - this.customFilesWatcher.close() - } - - if (this.nuxtRestartWatcher) { - this.nuxtRestartWatcher.close() + for (const watcher in this.watchers) { + if (this.watchers[watcher]) { + this.watchers[watcher].close() + } } this.compilersWatching.forEach(watching => watching.close()) diff --git a/test/fixtures/cli/nuxt.config.js b/test/fixtures/cli/nuxt.config.js index 086f6dbc5f..115f15862a 100644 --- a/test/fixtures/cli/nuxt.config.js +++ b/test/fixtures/cli/nuxt.config.js @@ -1,3 +1,3 @@ export default { - watch: ['./custom.file'] + watch: ['~/custom.file'] }