From 50c6d3bac0fd6aaf88bdd640ef53b558592fc50c Mon Sep 17 00:00:00 2001 From: Dmitry Chirkin Date: Mon, 9 Jul 2018 13:41:03 +0300 Subject: [PATCH] docs: update main function return values, add html-webpack-plugin example (#98) * Updated Readme.md Updated Readme.md to reflect actual middleware behavior, also fixed actual name of the property containing devMiddleware Added example usage with html-webpack-plugin * chore: slight verbiage modification --- README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c258b9e..4bb287c 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,14 @@ koaWebpack({ .. options .. }) ### koaWebpack([options]) -Returns an `Object` containing: +Returns a `Promise` which resolves the server `middleware` containing the +following additional properties: - `close(callback)` *(Function)* - Closes both the instance of `webpack-dev-middleware` and `webpack-hot-client`. Accepts a single `Function` callback parameter that is executed when complete. -- `client` *(Object)* - An instance of `webpack-hot-client`. -- `dev` *(Object)* - An instance of `webpack-dev-middleware` +- `hotClient` *(Object)* - An instance of `webpack-hot-client`. +- `devMiddleware` *(Object)* - An instance of `webpack-dev-middleware` ## Options @@ -164,6 +165,24 @@ For more details please refer to: [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware#server-side-rendering) +## Using with html-webpack-plugin + +When using with html-webpack-plugin, you can access dev-middleware in-memory filesystem to serve index.html file: + +```js +koaWebpack({ + config: webpackConfig +}).then(middleware => { + app.use(middleware) + + app.use(async ctx => { + const filename = path.resolve(webpackConfig.output.path, 'index.html') + ctx.response.type = 'html' + ctx.response.body = middleware.devMiddleware.fileSystem.createReadStream(filename) + }) +}) +``` + ## Contributing Please take a moment to read our contributing guidelines if you haven't yet done so. @@ -198,4 +217,4 @@ This module started as a fork of [chat-url]: https://gitter.im/webpack/webpack [size]: https://packagephobia.now.sh/badge?p=koa-webpack -[size-url]: https://packagephobia.now.sh/result?p=koa-webpack \ No newline at end of file +[size-url]: https://packagephobia.now.sh/result?p=koa-webpack