fix: add option to rewatch on path after raw fs event (#4717)

This commit is contained in:
Pim 2019-01-09 11:48:28 +01:00 committed by Pooya Parsa
parent 2e62fbe3b2
commit 9c6df495d8
2 changed files with 46 additions and 12 deletions

View File

@ -470,21 +470,30 @@ export default class Builder {
// -- Loading indicator -- // -- Loading indicator --
if (this.options.loadingIndicator.name) { if (this.options.loadingIndicator.name) {
const indicatorPath1 = path.resolve( let indicatorPath = path.resolve(
this.template.dir, this.template.dir,
'views/loading', 'views/loading',
this.options.loadingIndicator.name + '.html' this.options.loadingIndicator.name + '.html'
) )
const indicatorPath2 = this.nuxt.resolver.resolveAlias(
let customIndicator = false
if (!fsExtra.existsSync(indicatorPath)) {
indicatorPath = this.nuxt.resolver.resolveAlias(
this.options.loadingIndicator.name this.options.loadingIndicator.name
) )
const indicatorPath = fsExtra.existsSync(indicatorPath1)
? indicatorPath1 if (fsExtra.existsSync(indicatorPath)) {
: fsExtra.existsSync(indicatorPath2) ? indicatorPath2 : null customIndicator = true
} else {
indicatorPath = null
}
}
if (indicatorPath) { if (indicatorPath) {
templatesFiles.push({ templatesFiles.push({
src: indicatorPath, src: indicatorPath,
dst: 'loading.html', dst: 'loading.html',
custom: customIndicator,
options: this.options.loadingIndicator options: this.options.loadingIndicator
}) })
} else { } else {
@ -532,11 +541,17 @@ export default class Builder {
interpolate: /<%=([\s\S]+?)%>/g interpolate: /<%=([\s\S]+?)%>/g
} }
// Add vue-app template dir to watchers
this.options.build.watch.push(this.template.dir)
// Interpret and move template files to .nuxt/ // Interpret and move template files to .nuxt/
await Promise.all( await Promise.all(
templatesFiles.map(async ({ src, dst, options, custom }) => { templatesFiles.map(async ({ src, dst, options, custom }) => {
// Add template to watchers // Add custom templates to watcher
if (custom) {
this.options.build.watch.push(src) this.options.build.watch.push(src)
}
// Render template to dst // Render template to dst
const fileContent = await fsExtra.readFile(src, 'utf8') const fileContent = await fsExtra.readFile(src, 'utf8')
let content let content
@ -612,9 +627,27 @@ export default class Builder {
...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 (refresh) refreshFiles()
this.watchers.custom = chokidar this.watchers.custom = chokidar
.watch(customPatterns, options) .watch(customPatterns, options)
.on('change', refreshFiles) .on('change', refreshFiles)
const rewatchOnRawEvents = this.options.watchers.rewatchOnRawEvents
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()
} }
watchRestart() { watchRestart() {

View File

@ -64,6 +64,7 @@ export default () => ({
// Watch // Watch
watch: [], watch: [],
watchers: { watchers: {
rewatchOnRawEvents: env.linux ? ['rename'] : undefined,
webpack: {}, webpack: {},
chokidar: { chokidar: {
ignoreInitial: true ignoreInitial: true