Skip to content

Commit

Permalink
docs: add client.logging example (#3722)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Aug 23, 2021
1 parent 50702e4 commit 3a04c60
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/client/logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# client.logging Option

`'log' | 'info' | 'warn' | 'error' | 'none' | 'verbose'`

Allows to set log level in the browser, e.g. before reloading, before an error or when Hot Module Replacement is enabled.

**webpack.config.js**

```js
module.exports = {
// ...
devServer: {
client: {
logging: "info",
},
},
};
```

Usage via CLI:

```shell
npx webpack serve --open --client-logging info
```

## What Should Happen

1. The script should open `http://localhost:8080/` in your default browser.
2. You should see an overlay in browser for compilation warnings.
3. Open the console in your browser's devtools.

In the devtools console you should see:

```
[HMR] Waiting for update signal from WDS...
[webpack-dev-server] Hot Module Replacement enabled.
[webpack-dev-server] Live Reloading enabled.
[webpack-dev-server] Warnings while compiling.
[webpack-dev-server] Manual warnings produced during compilation.
```
6 changes: 6 additions & 0 deletions examples/client/logging/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

const target = document.querySelector("#target");

target.classList.add("pass");
target.innerHTML = "Success!";
29 changes: 29 additions & 0 deletions examples/client/logging/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

// our setup function adds behind-the-scenes bits to the config that all of our
// examples need
const { setup } = require("../../util");

module.exports = setup({
context: __dirname,
entry: "./app.js",
plugins: [
{
apply(compiler) {
compiler.hooks.thisCompilation.tap(
"warnings-webpack-plugin",
(compilation) => {
compilation.warnings.push(
new Error("Manual warnings produced during compilation.")
);
}
);
},
},
],
devServer: {
client: {
logging: "info",
},
},
});

0 comments on commit 3a04c60

Please sign in to comment.