diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index b3b10750bd..7eec5f273d 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -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( - this.options.loadingIndicator.name - ) - const indicatorPath = fsExtra.existsSync(indicatorPath1) - ? indicatorPath1 - : fsExtra.existsSync(indicatorPath2) ? indicatorPath2 : null + + let customIndicator = false + if (!fsExtra.existsSync(indicatorPath)) { + indicatorPath = this.nuxt.resolver.resolveAlias( + this.options.loadingIndicator.name + ) + + 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 - this.options.build.watch.push(src) + // 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) - this.watchers.custom = chokidar - .watch(customPatterns, options) - .on('change', refreshFiles) + 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() { diff --git a/packages/config/src/config/_common.js b/packages/config/src/config/_common.js index 0cc0464871..58da57b087 100644 --- a/packages/config/src/config/_common.js +++ b/packages/config/src/config/_common.js @@ -64,6 +64,7 @@ export default () => ({ // Watch watch: [], watchers: { + rewatchOnRawEvents: env.linux ? ['rename'] : undefined, webpack: {}, chokidar: { ignoreInitial: true