mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 22:51:02 +00:00
refactor client watch
Fixes duplicate READY message
This commit is contained in:
parent
6945479984
commit
750276b3f6
17
lib/build.js
17
lib/build.js
@ -139,8 +139,8 @@ export function * build () {
|
|||||||
function * buildFiles () {
|
function * buildFiles () {
|
||||||
if (this.dev) {
|
if (this.dev) {
|
||||||
debug('Adding webpack middleware...')
|
debug('Adding webpack middleware...')
|
||||||
const clientCompiler = createWebpackMiddleware.call(this)
|
createWebpackMiddleware.call(this)
|
||||||
webpackWatchAndUpdate.call(this, clientCompiler)
|
webpackWatchAndUpdate.call(this)
|
||||||
watchPages.call(this)
|
watchPages.call(this)
|
||||||
} else {
|
} else {
|
||||||
debug('Building files...')
|
debug('Building files...')
|
||||||
@ -386,6 +386,7 @@ function createWebpackMiddleware () {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
const clientCompiler = webpack(clientConfig)
|
const clientCompiler = webpack(clientConfig)
|
||||||
|
this.clientCompiler = clientCompiler
|
||||||
// Add the middleware to the instance context
|
// Add the middleware to the instance context
|
||||||
this.webpackDevMiddleware = pify(require('webpack-dev-middleware')(clientCompiler, {
|
this.webpackDevMiddleware = pify(require('webpack-dev-middleware')(clientCompiler, {
|
||||||
publicPath: clientConfig.output.publicPath,
|
publicPath: clientConfig.output.publicPath,
|
||||||
@ -406,14 +407,14 @@ function createWebpackMiddleware () {
|
|||||||
interpolate: /{{([\s\S]+?)}}/g
|
interpolate: /{{([\s\S]+?)}}/g
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.watchHandler()
|
||||||
})
|
})
|
||||||
return clientCompiler
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function webpackWatchAndUpdate (clientCompiler) {
|
function webpackWatchAndUpdate () {
|
||||||
const MFS = require('memory-fs') // <- dependencies of webpack
|
const MFS = require('memory-fs') // <- dependencies of webpack
|
||||||
const serverFS = new MFS()
|
const serverFS = new MFS()
|
||||||
const clientFS = clientCompiler.outputFileSystem
|
const clientFS = this.clientCompiler.outputFileSystem
|
||||||
const serverConfig = getWebpackServerConfig.call(this)
|
const serverConfig = getWebpackServerConfig.call(this)
|
||||||
const serverCompiler = webpack(serverConfig)
|
const serverCompiler = webpack(serverConfig)
|
||||||
const bundlePath = join(serverConfig.output.path, 'server-bundle.json')
|
const bundlePath = join(serverConfig.output.path, 'server-bundle.json')
|
||||||
@ -428,13 +429,13 @@ function webpackWatchAndUpdate (clientCompiler) {
|
|||||||
} else if (!manifestExists) {
|
} else if (!manifestExists) {
|
||||||
debug('Waiting for client manifest...')
|
debug('Waiting for client manifest...')
|
||||||
} else {
|
} else {
|
||||||
const bundle = serverFS.readFileSync(bundlePath, 'utf-8')
|
const bundle = serverFS.readFileSync(bundlePath, 'utf8')
|
||||||
const manifest = clientFS.readFileSync(manifestPath, 'utf-8')
|
const manifest = clientFS.readFileSync(manifestPath, 'utf8')
|
||||||
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
|
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.watchHandler = watchHandler
|
||||||
this.webpackServerWatcher = serverCompiler.watch(this.options.watchers.webpack, watchHandler)
|
this.webpackServerWatcher = serverCompiler.watch(this.options.watchers.webpack, watchHandler)
|
||||||
this.webpackClientWatcher = clientCompiler.watch(this.options.watchers.webpack, watchHandler)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function webpackRunClient () {
|
function webpackRunClient () {
|
||||||
|
Loading…
Reference in New Issue
Block a user