From 12727d116520cd6c785406d40839a4a7aa3a8e8f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 12 May 2017 12:45:37 +0430 Subject: [PATCH] [modules] Watch for template changes `build.watch` option was added --- lib/build.js | 7 ++++--- lib/module.js | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/build.js b/lib/build.js index 756f5605c8..cc7b0b30d1 100644 --- a/lib/build.js +++ b/lib/build.js @@ -58,7 +58,8 @@ const defaults = { plugins: [], babel: {}, postcss: [], - templates: [] + templates: [], + watch: [] } const defaultsLoaders = [ { @@ -512,7 +513,7 @@ function watchPages () { r(this.srcDir, 'pages/**/*.vue'), r(this.srcDir, 'layouts/*.vue'), r(this.srcDir, 'layouts/**/*.vue') - ] + ].concat(this.options.build.watch) const options = Object.assign({}, this.options.watchers.chokidar, { ignoreInitial: true }) @@ -520,7 +521,7 @@ function watchPages () { const refreshFiles = _.debounce(() => { co(generateRoutesAndFiles.bind(this)) }, 200) - this.pagesFilesWatcher = chokidar.watch(patterns, options) + this.pagesFilesWatcher = chokidar.watch(_.uniq(patterns), options) .on('add', refreshFiles) .on('unlink', refreshFiles) } diff --git a/lib/module.js b/lib/module.js index 51009a2499..acdede2236 100755 --- a/lib/module.js +++ b/lib/module.js @@ -34,7 +34,6 @@ class Module { // Generate unique and human readable dst filename const dst = template.fileName || (path.basename(srcPath.dir) + '.' + srcPath.name + '.' + hash(src) + '.' + srcPath.ext) - // Add to templates list const templateObj = { src, @@ -42,9 +41,15 @@ class Module { options: template.options } this.options.build.templates.push(templateObj) + // Watch template for changes + this.addWatch(src) return templateObj } + addWatch (pattern) { + this.options.build.watch.push(pattern) + } + addPlugin (template) { const {dst} = this.addTemplate(template) // Add to nuxt plugins