feat: implement hot module replacement middleware#2321
Conversation
|
The first compiler entry used `../../outputs/...` which escaped the test directory and wrote artifacts to the repository root, outside of the `/test/outputs` paths covered by `.gitignore` and `.prettierignore`.
Adds a `hot: true | { path, heartbeat, log, statsOptions }` option that
turns the dev middleware into a Server-Sent Events endpoint publishing
`building`, `built` and `sync` payloads from the webpack compiler.
The hot endpoint defaults to `/__webpack_hmr` and is served by the
existing middleware - no separate `app.use()` call is required.
`close()` tears down clients and the heartbeat timer.
Covers schema validation of the `hot` option (success and failure cases with snapshots), unit tests for `pathMatch`, `formatErrors`, `buildModuleMap` and `createEventStream`, and integration tests that verify SSE headers, the default and custom hot paths, MultiCompiler support, `close()` teardown, and the `log` option (custom function and `log: false`).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## hot-middleware #2321 +/- ##
==================================================
+ Coverage 92.70% 92.78% +0.07%
==================================================
Files 3 4 +1
Lines 1001 1192 +191
Branches 311 364 +53
==================================================
+ Hits 928 1106 +178
- Misses 65 76 +11
- Partials 8 10 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ports the remaining unit-level cases from webpack-hot-middleware that were not already covered by the framework matrix in middleware.test.js: - the public `publish()` API broadcasts custom payloads - a client connecting after a build receives a `sync` event initialised from the last stats - HTTP/1 clients get `Connection: keep-alive`, HTTP/2 clients do not - when `stats.name` is empty the published payload falls back to `compilation.name` - a single broadcast reaches every attached client - after `close()` further compiler events do not produce writes
| timings: true, | ||
| hash: true, | ||
| errors: true, | ||
| warnings: true, |
There was a problem hiding this comment.
Ideally we need only require stats, it is slow down build
Summary
What kind of change does this PR introduce?
Did you add tests for your changes?
Does this PR introduce a breaking change?
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Use of AI