refactor client watch

Fixes duplicate READY message
This commit is contained in:
Pooya Parsa 2017-04-27 21:14:31 +04:30
parent 6945479984
commit 750276b3f6

View File

@ -139,8 +139,8 @@ export function * build () {
function * buildFiles () {
if (this.dev) {
debug('Adding webpack middleware...')
const clientCompiler = createWebpackMiddleware.call(this)
webpackWatchAndUpdate.call(this, clientCompiler)
createWebpackMiddleware.call(this)
webpackWatchAndUpdate.call(this)
watchPages.call(this)
} else {
debug('Building files...')
@ -386,6 +386,7 @@ function createWebpackMiddleware () {
})
)
const clientCompiler = webpack(clientConfig)
this.clientCompiler = clientCompiler
// Add the middleware to the instance context
this.webpackDevMiddleware = pify(require('webpack-dev-middleware')(clientCompiler, {
publicPath: clientConfig.output.publicPath,
@ -406,14 +407,14 @@ function createWebpackMiddleware () {
interpolate: /{{([\s\S]+?)}}/g
})
}
this.watchHandler()
})
return clientCompiler
}
function webpackWatchAndUpdate (clientCompiler) {
function webpackWatchAndUpdate () {
const MFS = require('memory-fs') // <- dependencies of webpack
const serverFS = new MFS()
const clientFS = clientCompiler.outputFileSystem
const clientFS = this.clientCompiler.outputFileSystem
const serverConfig = getWebpackServerConfig.call(this)
const serverCompiler = webpack(serverConfig)
const bundlePath = join(serverConfig.output.path, 'server-bundle.json')
@ -428,13 +429,13 @@ function webpackWatchAndUpdate (clientCompiler) {
} else if (!manifestExists) {
debug('Waiting for client manifest...')
} else {
const bundle = serverFS.readFileSync(bundlePath, 'utf-8')
const manifest = clientFS.readFileSync(manifestPath, 'utf-8')
const bundle = serverFS.readFileSync(bundlePath, 'utf8')
const manifest = clientFS.readFileSync(manifestPath, 'utf8')
createRenderer.call(this, JSON.parse(bundle), JSON.parse(manifest))
}
}
this.watchHandler = watchHandler
this.webpackServerWatcher = serverCompiler.watch(this.options.watchers.webpack, watchHandler)
this.webpackClientWatcher = clientCompiler.watch(this.options.watchers.webpack, watchHandler)
}
function webpackRunClient () {