[modules] Watch for template changes

`build.watch` option was added
This commit is contained in:
Pooya Parsa 2017-05-12 12:45:37 +04:30
parent 2c37811032
commit 12727d1165
2 changed files with 10 additions and 4 deletions

View File

@ -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)
}

View File

@ -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