fix(builder): watch for `pages/` creation when default page displayed (#5753)

This commit is contained in:
Sébastien Chopin 2019-05-23 12:19:37 +02:00 committed by Pooya Parsa
parent 21aaef3b48
commit e75d65b268
2 changed files with 28 additions and 1 deletions

View File

@ -604,7 +604,7 @@ export default class Builder {
patterns.push(r(src, this.options.dir.store)) patterns.push(r(src, this.options.dir.store))
} }
if (this._nuxtPages) { if (this._nuxtPages && !this._defaultPage) {
patterns.push( patterns.push(
r(src, this.options.dir.pages), r(src, this.options.dir.pages),
...rGlob(this.options.dir.pages) ...rGlob(this.options.dir.pages)
@ -657,6 +657,10 @@ export default class Builder {
if (this.ignore.ignoreFile) { if (this.ignore.ignoreFile) {
nuxtRestartWatch.push(this.ignore.ignoreFile) nuxtRestartWatch.push(this.ignore.ignoreFile)
} }
// If default page displayed, watch for first page creation
if (this._nuxtPages && this._defaultPage) {
nuxtRestartWatch.push(path.join(this.options.srcDir, this.options.dir.pages))
}
// If store not activated, watch for a file in the directory // If store not activated, watch for a file in the directory
if (!this.options.store) { if (!this.options.store) {
nuxtRestartWatch.push(path.join(this.options.srcDir, this.options.dir.store)) nuxtRestartWatch.push(path.join(this.options.srcDir, this.options.dir.store))

View File

@ -87,6 +87,29 @@ describe('builder: builder watch', () => {
expect(r).nthCalledWith(5, '/var/nuxt/src', '/var/nuxt/src/store') expect(r).nthCalledWith(5, '/var/nuxt/src', '/var/nuxt/src/store')
}) })
test('should NOT watch pages files on client if _defaultPage=true', () => {
const nuxt = createNuxt()
nuxt.options.srcDir = '/var/nuxt/src'
nuxt.options.dir = {
layouts: '/var/nuxt/src/layouts',
pages: '/var/nuxt/src/pages',
store: '/var/nuxt/src/store',
middleware: '/var/nuxt/src/middleware'
}
nuxt.options.build.watch = []
nuxt.options.watchers = {
chokidar: { test: true }
}
const builder = new Builder(nuxt, {})
builder._nuxtPages = true
builder._defaultPage = true
r.mockImplementation((dir, src) => src)
builder.watchClient()
expect(r).toBeCalledTimes(4)
})
test('should watch pages files', () => { test('should watch pages files', () => {
const nuxt = createNuxt() const nuxt = createNuxt()
nuxt.options.srcDir = '/var/nuxt/src' nuxt.options.srcDir = '/var/nuxt/src'