You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f35a596
Browse filesBrowse the repository at this point in the historyBrowse files
feat(hot): every browser option set in node or on the query, one name each (#2436)
* feat(hot): every browser option set in node or on the query
`hot.client` and the injected entry's query were two overlapping option sets
with a gap on each side. They are one set now.
`hot`, `liveReload` and `urlPrefix` were readable from the query alone and can
be set in node:
middleware(compiler, {
hot: { client: { hot: false, liveReload: true, urlPrefix: "my-server" } },
})
`transport`, `path` and `name` go the other way: the middleware set them and
they could not be overridden, which left no way to point a client at an
endpoint reached through a proxy or on another origin. They are defaults now —
the resolved `hot.transport`, the resolved `hot.path` and the compilation's
name — and `hot.client` is spread over them, so nothing changes for anyone not
setting them.
middleware(compiler, {
hot: { client: { path: "wss://dev.example.com/__webpack_hmr" } },
})
A `hot.transport` of your own gets a client too when `hot.client.transport`
says which of the two built-in protocols yours carries; without it the client
is still yours to add. Overriding the transport without an endpoint of its own
points the client back at this middleware speaking the wrong protocol, so that
combination is warned about rather than left as a page that never connects.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
* refactor(client): one name per browser option, no aliases
The query had picked up two second spellings from webpack-dev-server —
`webSocketURL` for `path` and `live-reload` for `liveReload` — and the page-url
parameter was spelled `-live-reload` while the option it turns off is
`liveReload`. Dropped all three: each option is one name, in `hot.client`, in
the entry query and in the page parameters alike. dev-server maps its own
spellings when it moves over.
`?webpack-dev-middleware-live-reload=false` is now
`?webpack-dev-middleware-liveReload=false`, still matched case-insensitively.
None of this was released.
Added a test that reads the names the client acts on out of `setOverrides` and
the names `hot.client` accepts out of the schema, and fails unless the two
lists are equal — an option with only one of the two spellings, or a second
name for one setting, breaks it rather than going unnoticed.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
---------
Co-authored-by: Claude Opus 5 <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+45-14Lines changed: 45 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -541,7 +541,7 @@ Two things do change, and `hot.inject: false` turns both off:
541
541
542
542
One caveat: if the compiler was already watching before the middleware was created, the runtime appears from the next build onwards rather than the first one. Create the middleware before starting the watch to avoid it.
543
543
544
-
No client is added when [`hot.transport`](#hottransport) is a function either — the built-in one speaks Server-Sent Events and WebSocket, and a transport of your own carries whatever protocol you wrote it to carry, so the client that speaks it is yours to add. `HotModuleReplacementPlugin` is still applied for you. `hot.inject: false` silences the reminder, and turns that off as well — apply the plugin yourself if you use it.
544
+
No client is added when [`hot.transport`](#hottransport) is a function either — the built-in one speaks Server-Sent Events and WebSocket, and a transport of your own carries whatever protocol you wrote it to carry, so the client that speaks it is yours to add unless [`hot.client.transport`](#client-options) says which of the two yours speaks. `HotModuleReplacementPlugin` is still applied for you. `hot.inject: false` silences the reminder, and turns that off as well — apply the plugin yourself if you use it.
545
545
546
546
The [client options](#client-options) below are set on the middleware, next to
547
547
the rest of the hot configuration, and the injected entry carries them to the
@@ -555,9 +555,34 @@ app.use(
555
555
);
556
556
```
557
557
558
-
`transport`, `path` and `name` are not accepted there: the middleware knows all
559
-
three already and sets them itself, so the runtime cannot be pointed somewhere
560
-
the server is not listening.
558
+
Every option below can be set either way, and they are the same options: what
559
+
`hot.client` takes is what the query carries. `transport`, `path` and `name`
560
+
differ only in having a value the middleware already knows — the resolved
561
+
[`hot.transport`](#hottransport), the resolved [`hot.path`](#hotpath) and the
562
+
compilation's own name — so setting one replaces that default rather than
563
+
adding to it. That is what a page reaching the endpoint through a proxy or on
|`transport`|`string`|`"sse"`| How the events are carried: `"sse"` or `"ws"`. Must match the server [`hot.transport`](#hottransport). |
606
-
|`path`|`string`|`/__webpack_hmr`|Path the endpoint is served at. Must match the server `hot.path`. |
636
+
|`transport`|`string`|`"sse"`| How the events are carried: `"sse"` or `"ws"`. Defaults to the server [`hot.transport`](#hottransport); override it only together with `path`, since a client asking this endpoint for a protocol it does not serve never connects — the middleware warns when it sees that.|
637
+
|`path`|`string`|`/__webpack_hmr`|Where the runtime connects. Defaults to the server [`hot.path`](#hotpath); set it to an absolute url (`wss://dev.example.com/__webpack_hmr`) for an endpoint on another origin or behind a proxy.|
607
638
|`timeout`|`number`|`20000`| Heartbeat watchdog timeout in milliseconds, and the interval between reconnections under `"sse"`. |
608
639
|`reconnect`|`number`|`10`| How many times `"ws"` reconnects before giving up. `"sse"` retries for as long as the page is open and ignores this. |
609
640
|`overlay`|`boolean\|Object`|`true`| In-page overlay for problems: a boolean, or a JSON object — see [overlay options](#client-overlay-options). Same value shape as webpack-dev-server's [`client.overlay`](https://webpack.js.org/configuration/dev-server/#overlay), plus a few webpack-dev-middleware extensions. |
610
-
|`hot`|`boolean`|`true`| Apply a build through Hot Module Replacement. Set to `false` for a project without `HotModuleReplacementPlugin`, and the page is reloaded instead — see `live-reload`.|
611
-
|`live-reload`|`boolean`|`true`| Reload the page on a build that changed something, when `hot` is off. A build that changed nothing is left alone. Set both this and `hot` to `false` and a build reaches the page only when you reload it yourself. |
612
-
|`reload`|`boolean`|`true`| Fall back to a full page reload when an update cannot be applied through HMR (e.g. recovering from a broken build). Enabled by default, unlike webpack-hot-middleware; set to `false` to keep HMR-only. Unrelated to `live-reload`: this one is about an update that was tried. |
613
-
|`urlPrefix`|`string`|`"webpack-dev-middleware"`| Names the page-url parameters that turn `hot` and `live-reload` off for a single page — see [opting one page out](#opting-one-page-out). Change it if you are building a server of your own and want parameters named after it. |
641
+
|`hot`|`boolean`|`true`| Apply a build through Hot Module Replacement. Set to `false` for a project without `HotModuleReplacementPlugin`, and the page is reloaded instead — see `liveReload`. |
642
+
|`liveReload`|`boolean`|`true`| Reload the page on a build that changed something, when `hot` is off. A build that changed nothing is left alone. Set both this and `hot` to `false` and a build reaches the page only when you reload it yourself. |
643
+
|`reload`|`boolean`|`true`| Fall back to a full page reload when an update cannot be applied through HMR (e.g. recovering from a broken build). Enabled by default, unlike webpack-hot-middleware; set to `false` to keep HMR-only. Unrelated to `liveReload`: this one is about an update that was tried.|
644
+
|`urlPrefix`|`string`|`"webpack-dev-middleware"`| Names the page-url parameters that turn `hot` and `liveReload` off for a single page — see [opting one page out](#opting-one-page-out). Change it if you are building a server of your own and want parameters named after it.|
614
645
|`logging`|`string`|`"info"`| Logger level — one of `"none"`, `"error"`, `"warn"`, `"info"`, `"log"`, `"verbose"`. Uses webpack's runtime logger. |
615
646
|`name`|`string`|`""`| Restrict updates to a specific compilation name (useful with multi-compiler). |
616
647
|`autoConnect`|`boolean`|`true`| Connect on load; set to `false` and call `setOptionsAndConnect()` manually. |
@@ -813,22 +844,22 @@ Three layers, from build to presentation:
813
844
814
845
### Opting one page out
815
846
816
-
A page can turn `hot` or `live-reload` off for itself with a url parameter,
847
+
A page can turn `hot` or `liveReload` off for itself with a url parameter,
817
848
without changing anything the project is configured with — useful when you are
818
849
working _in_ a page that keeps reloading under you:
The `webpack-dev-middleware` part is the client's [`urlPrefix`](#client-options). The name is matched whole and case-insensitively, and only the value `false` turns anything off — a parameter that merely contains those words, or a value such as `falsehood`, is left alone.
856
+
The `webpack-dev-middleware` part is the client's [`urlPrefix`](#client-options), so a server built on this middleware can set `hot.client.urlPrefix` and name these parameters after itself. What follows it is the option, spelled the one way the option is spelled. The name is matched whole and case-insensitively, and only the value `false` turns anything off — a parameter that merely contains those words, or a value such as `falsehood`, is left alone.
826
857
827
858
### Reloading the page from the server
828
859
829
860
Some changes belong to no compilation — a file served straight from disk, for
830
861
instance — so nothing tells the page it is stale. Publish a `reload` and it
831
-
loads itself again, whatever `hot` and `live-reload` are set to:
862
+
loads itself again, whatever `hot` and `liveReload` are set to:
0 commit comments