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 --
if (this.options.loadingIndicator.name) {
const indicatorPath1 = path.resolve(
let indicatorPath = path.resolve(
this.template.dir,
'views/loading',
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
)
const indicatorPath = fsExtra.existsSync(indicatorPath1)
? indicatorPath1
: fsExtra.existsSync(indicatorPath2) ? indicatorPath2 : null
if (fsExtra.existsSync(indicatorPath)) {
customIndicator = true
} else {
indicatorPath = null
}
}
if (indicatorPath) {
templatesFiles.push({
src: indicatorPath,
dst: 'loading.html',
custom: customIndicator,
options: this.options.loadingIndicator
})
} else {
@ -532,11 +541,17 @@ export default class Builder {
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/
await Promise.all(
templatesFiles.map(async ({ src, dst, options, custom }) => {
// Add template to watchers
// Add custom templates to watcher
if (custom) {
this.options.build.watch.push(src)
}
// Render template to dst
const fileContent = await fsExtra.readFile(src, 'utf8')
let content
@ -612,9 +627,27 @@ export default class Builder {
...Object.values(omit(this.options.build.styleResources, ['options']))
]).map(upath.normalizeSafe)
const watchCustom = (refresh) => {
if (refresh) refreshFiles()
this.watchers.custom = chokidar
.watch(customPatterns, options)
.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() {

View File

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