Skip to content

Commit 931ef71

Browse files
feat: reuse webpack-dev-middleware's browser runtime
This server has no client of its own any more. `client-src/` is gone — the runtime, the error overlay, the progress indicator, the logger, the socket wrapper and the WebSocket client, around two thousand lines that existed in near-duplicate in both projects — and the middleware's hot option drives all of it, including putting the entry and `HotModuleReplacementPlugin` into the compilation. Nothing about a configuration changes. Every option keeps its name and its meaning and is mapped onto the middleware's vocabulary in `lib/hotOptions.js`: `hot`/`liveReload` become one `apply` mode, `client.reconnect` becomes `connect.retries`, `client.webSocketURL` is already the shape the middleware's `hot.client.path` takes, and the overlay is passed through with this project's own element id so anything querying for it still finds it. The `webpack-dev-server/client/*` paths are generated re-exports of the middleware's client, so importing them resolves to what it always did. The paths that were only this bundle's internals are no longer published. Protection stays here. `allowedHosts`, the `Origin` checks and the same-origin rule are unchanged: the middleware is handed `cors: true` and no token, which is it applying no policy of its own, and every connection is judged here before anything is published to it. A handshake is refused before it completes rather than after, since the middleware exposes the upgrade rather than taking the server over. A `webSocketServer` of your own still works. A class, a module exporting one, or options giving the socket a port or a server of its own are wrapped into the shape the middleware asks a custom transport for, so there is one path from a build to a page either way, and `BaseServer` keeps its export. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
1 parent 802c20d commit 931ef71

42 files changed

Lines changed: 708 additions & 3589 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"webpack-dev-server": minor
3+
---
4+
5+
The browser runtime is webpack-dev-middleware's now. This server has no client of its own: `client-src/` is gone — the runtime, the error overlay, the progress indicator, the logger, the socket wrapper and the WebSocket client, around two thousand lines that existed in near-duplicate in both projects.
6+
7+
What this means for a configuration is nothing. Every option keeps its name and its meaning: `hot`, `liveReload`, `client.overlay`, `client.progress`, `client.logging`, `client.reconnect`, `client.webSocketURL`, `client.webSocketTransport`, `webSocketServer`, `allowedHosts`. They are mapped onto the middleware's `hot` option, in `lib/hotOptions.js`, and what used to be two implementations of the same ideas is one.
8+
9+
What it means for the `webpack-dev-server/client/*` paths is that they re-export the middleware's client, so an import of `webpack-dev-server/client/index.js`, `client/overlay.js`, `client/progress.js` or `client/clients/WebSocketClient.js` resolves to the same thing it always did. The paths that were only this bundle's internals — `client/socket.js`, `client/utils/log.js`, `client/utils/sendMessage.js` and `client/modules/logger/index.js` — are not published any more; the middleware's client has its own.
10+
11+
The overlay keeps its element id, `webpack-dev-server-client-overlay`, so anything querying for it still finds it. It also gains the middleware's extra overlay options, which this project did not have: `styles`, `ansiColors`, `openEditorEndpoint` and `paginate`.
12+
13+
**Protection stays here.** `allowedHosts`, the `Origin` checks and the same-origin rule are unchanged and still applied before anything is published to a client: the middleware is handed `cors: true` and no token, which is it applying no policy of its own, and every connection is judged here. A WebSocket handshake is refused before it completes rather than after, since the middleware exposes the upgrade rather than taking the server over.
14+
15+
**The wire protocol is the middleware's**, which is what changes for anyone reading the socket directly rather than through the client. `{ type: "ok" | "still-ok" | "invalid" | "hash" | "static-changed" | "progress-update" }` becomes `{ action: "built" | "sync" | "building" | "reload" | "progress" }`: `built` is a build that changed something and `sync` one that did not, errors and warnings arrive with the build that produced them rather than as messages of their own, and the configuration this server used to push to a client after the handshake is in the client's entry query instead. A client wired by hand therefore needs its options in that query — `?path=/ws&transport=ws&apply=hmr` — rather than waiting to be told.
16+
17+
**A `webSocketServer` of your own still works.** A class, a module that exports one, or options giving the socket a port or a server of its own are wrapped into the shape the middleware asks a custom transport for, so there is one path from a build to a page either way. `BaseServer` keeps its published export and its contract. An implementation that forwarded whatever it was handed does not notice; one that inspected the old message shape sees the new one.

‎README.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ See [**the documentation**][docs-url] for more use cases and options.
259259

260260
## Browser Support
261261

262-
While `webpack-dev-server` transpiles the client (browser) scripts to an ES5
263-
state, the project only officially supports the _last two versions of major
264-
browsers_. We simply don't have the resources to support every whacky
265-
browser out there.
262+
The browser runtime is [webpack-dev-middleware]'s, which ships as ES5 and uses
263+
no built-in newer than ES5 beyond `Promise`, the transport in use and what hot
264+
module replacement itself needs. As before, the project only officially
265+
supports the _last two versions of major browsers_. We simply don't have the
266+
resources to support every whacky browser out there.
267+
268+
[webpack-dev-middleware]: https://github.com/webpack/webpack-dev-middleware#client-options
266269

267270
If you find a bug with an obscure / old browser, we would actively welcome a
268271
Pull Request to resolve the bug.

‎client-src/clients/WebSocketClient.js‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎client-src/globals.d.ts‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)