Skip to content
Draft
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"finalhandler",
"hono",
"rspack",
"apos",
"malformed"
],
"ignorePaths": [
Expand Down
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,21 @@ entry: [

### Client options

| Name | Type | Default | Description |
| :-----------------: | :-------: | :--------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path` | `string` | `/__webpack_hmr` | Path the SSE endpoint is served at. Must match the server `hot.path`. |
| `timeout` | `number` | `20000` | Reconnection / heartbeat watchdog timeout in milliseconds. |
| `overlay` | `boolean` | `true` | Show compile-time errors in an in-page overlay. |
| `overlayWarnings` | `boolean` | `false` | Also show compile-time warnings in the overlay. |
| `overlayStyles` | `Object` | `{}` | JSON object of CSS overrides for the overlay container. Pass JSON-encoded value via query string. |
| `ansiColors` | `Object` | `{}` | JSON object overriding the ANSI → HTML color map used by the overlay. |
| `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). Set to `false` to keep HMR-only. |
| `logging` | `string` | `"info"` | Logger level — one of `"none"`, `"error"`, `"warn"`, `"info"`, `"log"`, `"verbose"`. Uses webpack's runtime logger. |
| `name` | `string` | `""` | Restrict updates to a specific compilation name (useful with multi-compiler). |
| `autoConnect` | `boolean` | `true` | Connect on load; set to `false` and call `setOptionsAndConnect()` manually. |
| `dynamicPublicPath` | `boolean` | `false` | Prefix `path` with `__webpack_public_path__` at runtime. |
| Name | Type | Default | Description |
| :-----------------------------: | :-------: | :--------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path` | `string` | `/__webpack_hmr` | Path the SSE endpoint is served at. Must match the server `hot.path`. |
| `timeout` | `number` | `20000` | Reconnection / heartbeat watchdog timeout in milliseconds. |
| `overlay` | `boolean` | `true` | Show compile-time errors in an in-page overlay. |
| `overlayWarnings` | `boolean` | `false` | Also show compile-time warnings in the overlay. |
| `overlayRuntimeErrors` | `boolean` | `true` | Also show uncaught runtime errors and unhandled promise rejections in the overlay. |
| `overlayTrustedTypesPolicyName` | `string` | `undefined` | Trusted Types policy name used for the overlay's HTML (for pages served with `require-trusted-types-for 'script'`). |
| `overlayStyles` | `Object` | `{}` | JSON object of CSS overrides for the overlay container. Pass JSON-encoded value via query string. |
| `ansiColors` | `Object` | `{}` | JSON object overriding the ANSI → HTML color map used by the overlay. |
| `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). Set to `false` to keep HMR-only. |
| `logging` | `string` | `"info"` | Logger level — one of `"none"`, `"error"`, `"warn"`, `"info"`, `"log"`, `"verbose"`. Uses webpack's runtime logger. |
| `name` | `string` | `""` | Restrict updates to a specific compilation name (useful with multi-compiler). |
| `autoConnect` | `boolean` | `true` | Connect on load; set to `false` and call `setOptionsAndConnect()` manually. |
| `dynamicPublicPath` | `boolean` | `false` | Prefix `path` with `__webpack_public_path__` at runtime. |

### Programmatic API

Expand Down Expand Up @@ -422,6 +424,23 @@ hotClient.useCustomOverlay({
hotClient.setOptionsAndConnect({ path: "/__hmr" });
```

The error overlay is also exposed as a standalone module so other tooling
(e.g. `webpack-dev-server`) can reuse it without the SSE client:

```js
import configureOverlay, {
clear,
showProblems,
} from "webpack-dev-middleware/client/overlay";

const overlay = configureOverlay({
// ansiColors, overlayStyles, trustedTypesPolicyName, catchRuntimeError
});

overlay.showProblems("errors", ["Something broke"]);
overlay.clear();
```

## API

`webpack-dev-middleware` also provides convenience methods that can be use to
Expand Down
17 changes: 16 additions & 1 deletion client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import { log, setLogLevel } from "./utils/log.js";
* @property {LogLevel} logging logger level
* @property {string} name limit updates to this compilation name
* @property {boolean} autoConnect connect immediately when the entry runs
* @property {Record<string, string | number>} overlayStyles overrides for the overlay container CSS
* @property {Record<string, string | number>} overlayStyles overrides for the overlay card CSS
* @property {boolean} overlayWarnings show warnings in the overlay too
* @property {boolean} overlayRuntimeErrors show uncaught runtime errors and unhandled rejections in the overlay
* @property {string} overlayTrustedTypesPolicyName Trusted Types policy name used for the overlay's HTML
* @property {Record<string, string | string[]>} ansiColors overrides for ANSI → HTML color mapping
*/

Expand All @@ -33,6 +35,8 @@ const options = {
autoConnect: true,
overlayStyles: {},
overlayWarnings: false,
overlayRuntimeErrors: true,
overlayTrustedTypesPolicyName: "",
ansiColors: {},
};

Expand Down Expand Up @@ -71,6 +75,15 @@ function setOverrides(overrides) {
options.overlayWarnings = overrides.overlayWarnings === "true";
}

if (overrides.overlayRuntimeErrors) {
options.overlayRuntimeErrors = overrides.overlayRuntimeErrors !== "false";
}

if (overrides.overlayTrustedTypesPolicyName) {
options.overlayTrustedTypesPolicyName =
overrides.overlayTrustedTypesPolicyName;
}

setLogLevel(options.logging);
}

Expand Down Expand Up @@ -200,6 +213,8 @@ function createReporter() {
overlay = configureOverlay({
ansiColors: options.ansiColors,
overlayStyles: options.overlayStyles,
catchRuntimeError: options.overlayRuntimeErrors,
trustedTypesPolicyName: options.overlayTrustedTypesPolicyName,
});
}

Expand Down
Loading
Loading