mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 22:51:02 +00:00
Improve chokidar watch on middleware and store
This commit is contained in:
parent
ea5881e64a
commit
c4962f09a9
13
lib/build.js
13
lib/build.js
@ -183,6 +183,7 @@ function * generateRoutesAndFiles () {
|
|||||||
'components/nuxt-link.js',
|
'components/nuxt-link.js',
|
||||||
'components/nuxt.vue'
|
'components/nuxt.vue'
|
||||||
]
|
]
|
||||||
|
this.options.store = fs.existsSync(join(this.srcDir, 'store'))
|
||||||
let templateVars = {
|
let templateVars = {
|
||||||
uniqBy: _.uniqBy,
|
uniqBy: _.uniqBy,
|
||||||
isDev: this.dev,
|
isDev: this.dev,
|
||||||
@ -195,7 +196,7 @@ function * generateRoutesAndFiles () {
|
|||||||
},
|
},
|
||||||
env: this.options.env,
|
env: this.options.env,
|
||||||
head: this.options.head,
|
head: this.options.head,
|
||||||
middleware: this.options.middleware,
|
middleware: fs.existsSync(join(this.srcDir, 'middleware')),
|
||||||
store: this.options.store,
|
store: this.options.store,
|
||||||
css: this.options.css,
|
css: this.options.css,
|
||||||
plugins: this.options.plugins.map((p) => {
|
plugins: this.options.plugins.map((p) => {
|
||||||
@ -248,7 +249,7 @@ function * generateRoutesAndFiles () {
|
|||||||
return writeFile(path, content, 'utf8')
|
return writeFile(path, content, 'utf8')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Fix webpack loop (https://github.com/webpack/watchpack/issues/25#issuecomment-287789288)
|
// Fix webpack loop (https://github.com/webpack/watchpack/issues/25#issuecomment-287789288)
|
||||||
const dateFS = Date.now() / 1000 - 10
|
const dateFS = Date.now() / 1000 - 30
|
||||||
return utimes(path, dateFS, dateFS)
|
return utimes(path, dateFS, dateFS)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -462,9 +463,11 @@ function createRenderer (bundle) {
|
|||||||
function watchPages () {
|
function watchPages () {
|
||||||
const patterns = [
|
const patterns = [
|
||||||
r(this.srcDir, 'pages'),
|
r(this.srcDir, 'pages'),
|
||||||
|
r(this.srcDir, 'layouts'),
|
||||||
|
r(this.srcDir, 'store'),
|
||||||
|
r(this.srcDir, 'middleware'),
|
||||||
r(this.srcDir, 'pages/*.vue'),
|
r(this.srcDir, 'pages/*.vue'),
|
||||||
r(this.srcDir, 'pages/**/*.vue'),
|
r(this.srcDir, 'pages/**/*.vue'),
|
||||||
r(this.srcDir, 'layouts'),
|
|
||||||
r(this.srcDir, 'layouts/*.vue'),
|
r(this.srcDir, 'layouts/*.vue'),
|
||||||
r(this.srcDir, 'layouts/**/*.vue')
|
r(this.srcDir, 'layouts/**/*.vue')
|
||||||
]
|
]
|
||||||
@ -473,11 +476,7 @@ function watchPages () {
|
|||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const refreshFiles = _.debounce(() => {
|
const refreshFiles = _.debounce(() => {
|
||||||
var d = Date.now()
|
|
||||||
co(generateRoutesAndFiles.bind(this))
|
co(generateRoutesAndFiles.bind(this))
|
||||||
.then(() => {
|
|
||||||
console.log('Time to gen:' + (Date.now() - d) + 'ms') // eslint-disable-line no-console
|
|
||||||
})
|
|
||||||
}, 200)
|
}, 200)
|
||||||
this.pagesFilesWatcher = chokidar.watch(patterns, options)
|
this.pagesFilesWatcher = chokidar.watch(patterns, options)
|
||||||
.on('add', refreshFiles)
|
.on('add', refreshFiles)
|
||||||
|
@ -59,11 +59,6 @@ class Nuxt {
|
|||||||
if (fs.existsSync(join(this.srcDir, 'store'))) {
|
if (fs.existsSync(join(this.srcDir, 'store'))) {
|
||||||
this.options.store = true
|
this.options.store = true
|
||||||
}
|
}
|
||||||
// If middleware defined, update middleware option to true
|
|
||||||
this.options.middleware = false
|
|
||||||
if (fs.existsSync(join(this.srcDir, 'middleware'))) {
|
|
||||||
this.options.middleware = true
|
|
||||||
}
|
|
||||||
// If app.html is defined, set the template path to the user template
|
// If app.html is defined, set the template path to the user template
|
||||||
this.options.appTemplatePath = resolve(__dirname, 'views/app.template.html')
|
this.options.appTemplatePath = resolve(__dirname, 'views/app.template.html')
|
||||||
if (fs.existsSync(join(this.srcDir, 'app.html'))) {
|
if (fs.existsSync(join(this.srcDir, 'app.html'))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user