Skip to content

Commit

Permalink
docs: update main function return values, add html-webpack-plugin exa…
Browse files Browse the repository at this point in the history
…mple (#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
  • Loading branch information
josser authored and shellscape committed Jul 9, 2018
1 parent 4634bd0 commit 50c6d3b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
[size-url]: https://packagephobia.now.sh/result?p=koa-webpack

0 comments on commit 50c6d3b

Please sign in to comment.