Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- next
- hot-middleware
pull_request:
branches:
- main
- next
- hot-middleware

permissions:
contents: read
Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ See [below](#other-servers) for an example of use with fastify.
| **[`writeToDisk`](#writetodisk)** | `boolean\|Function` | `false` | Instructs the module to write files to the configured location on disk as specified in your `webpack` configuration. |
| **[`outputFileSystem`](#outputfilesystem)** | `Object` | [`memfs`](https://github.com/streamich/memfs) | Set the default file system which will be used by webpack as primary destination of generated files. |
| **[`modifyResponseData`](#modifyresponsedata)** | `Function` | `undefined` | Allows to set up a callback to change the response data. |
| **[`hot`](#hot)** | `boolean\|Object` | `undefined` | Enables a Server-Sent Events endpoint that drives the browser HMR client. |
| **[`forwardError`](#forwarderror)** | `boolean` | `false` | Enable or disable forwarding errors to the next middleware. |

The middleware accepts an `options` Object. The following is a property reference for the Object.
Expand Down Expand Up @@ -312,6 +313,51 @@ middleware(compiler, {
});
```

### hot

Type: `Boolean | Object`
Default: `undefined`

Enables hot module replacement by serving a [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) endpoint that publishes the webpack compiler's `building`, `built` and `sync` events to connected clients. When `true`, defaults are used; pass an object to customise. Use this option together with the browser runtime shipped as `webpack-dev-middleware/client`.

```js
const webpack = require("webpack");

const compiler = webpack({
/* Webpack configuration with HotModuleReplacementPlugin and the client entry */
});

middleware(compiler, { hot: true });
```

#### `hot.path`

Type: `String`
Default: `'/__webpack_hmr'`

Path the SSE endpoint is served at. Must match the `path` option used by the client.

#### `hot.heartbeat`

Type: `Number`
Default: `10000`

Heartbeat interval (in milliseconds) used to keep the SSE connection alive when no compilation events are produced.

#### `hot.log`

Type: `Function | false`
Default: the dev middleware's infrastructure logger

Logger used to print build status (`webpack building...`, `webpack built <hash> in <ms>`). Pass `false` to disable logging from the hot middleware.

#### `hot.statsOptions`

Type: `Boolean | Object`
Default: `undefined`

Webpack stats options used when serializing compilation results for the SSE payload. Forwarded to `stats.toJson(...)`.

## API

`webpack-dev-middleware` also provides convenience methods that can be use to
Expand Down
Loading
Loading