Table of Contents
This module is basically a cleaned up version of vue-hackernews-2.0's setup-dev-server.js which utilizes koa instead of express. This module is consumed by koa-vue-ssr_proof-of-concept, which again was written using vue-hackernews-2.0 as reference.
In the hackernews project, the setup-dev-server.js
file was very complex. So
when I created my own vue ssr project it was beneficial to isolate that
complexity into its own module. The intention is to keep the rest of the server
code focused on problems particular to the application.
- Watches the template html file and updates the vue renderer when modified
- Connects koa-webpack to the koa application passing it the client webpack compiler for HMR
- Attaches a 'done' event handler to the client webpack compiler and updates the vue renderer with the new clientManifest
- Runs the ssr webpack compiler's
watch()
method, updating the renderer with the new ssr bundle every pass. - Returns a promise that:
- resolves when both the bundle and clientManifest are created.
- rejects if there is an error prior to the resolve. Errors occuring during the watch processes after the promise settles will be logged to stderr.
// All arguments are required
initDevServer({
koaApp: <instanceof Koa>
webpackConfigs: {
client: <webpack configuration>
ssr: <webpack configuration>
}
webpackHotClientPort: <integer>
templatePath: <path to index html file>
})
// resolves to
.then({
koaApp: <instanceof Koa>
getRenderer: () => <instanceof BundleRenderer>
})