Skip to content

Commit 5670835

Browse files
jossershellscape
authored andcommitted
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
1 parent 3230857 commit 5670835

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ koaWebpack({ .. options .. })
6060

6161
### koaWebpack([options])
6262

63-
Returns an `Object` containing:
63+
Returns a `Promise` which resolves the server `middleware` containing the
64+
following additional properties:
6465

6566
- `close(callback)` *(Function)* - Closes both the instance of `webpack-dev-middleware`
6667
and `webpack-hot-client`. Accepts a single `Function` callback parameter that is
6768
executed when complete.
68-
- `client` *(Object)* - An instance of `webpack-hot-client`.
69-
- `dev` *(Object)* - An instance of `webpack-dev-middleware`
69+
- `hotClient` *(Object)* - An instance of `webpack-hot-client`.
70+
- `devMiddleware` *(Object)* - An instance of `webpack-dev-middleware`
7071

7172
## Options
7273

@@ -164,6 +165,24 @@ For more details please refer to:
164165
[webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware#server-side-rendering)
165166

166167

168+
## Using with html-webpack-plugin
169+
170+
When using with html-webpack-plugin, you can access dev-middleware in-memory filesystem to serve index.html file:
171+
172+
```js
173+
koaWebpack({
174+
config: webpackConfig
175+
}).then(middleware => {
176+
app.use(middleware)
177+
178+
app.use(async ctx => {
179+
const filename = path.resolve(webpackConfig.output.path, 'index.html')
180+
ctx.response.type = 'html'
181+
ctx.response.body = middleware.devMiddleware.fileSystem.createReadStream(filename)
182+
})
183+
})
184+
```
185+
167186
## Contributing
168187

169188
Please take a moment to read our contributing guidelines if you haven't yet done so.

0 commit comments

Comments
 (0)