Skip to content

Commit

Permalink
docs: add examples for the client.reconnect option (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Oct 12, 2021
1 parent ec78aee commit 0153c69
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/client/reconnect/false/README.md
@@ -0,0 +1,38 @@
# client.reconnect: false

## false

Tells dev-server the number of times it should try to reconnect the client. When `false` it will not try to reconnect.

**webpack.config.js**

```js
module.exports = {
// ...
devServer: {
client: {
reconect: false,
},
},
};
```

Usage via CLI:

```shell
npx webpack serve --open --no-client-reconnect
```

## What Should Happen

1. The script should open `http://localhost:8080/` in your default browser.
2. Open the console tab in your browser's devtools.
3. Now close the server with `Ctrl+C` to disconnect the client.

In the devtools console you should see that webpack-dev-server is not trying to reconnect:

```
[webpack-dev-server] Hot Module Replacement enabled.
[webpack-dev-server] Live Reloading enabled.
[webpack-dev-server] Disconnected!
```
7 changes: 7 additions & 0 deletions examples/client/reconnect/false/app.js
@@ -0,0 +1,7 @@
"use strict";

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

target.classList.add("pass");
target.innerHTML =
"Success! <br> Now, open the console tab in your browser's devtools. Then, close the server with `Ctrl+C` to disconnect the client.";
15 changes: 15 additions & 0 deletions examples/client/reconnect/false/webpack.config.js
@@ -0,0 +1,15 @@
"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",
devServer: {
client: {
reconnect: false,
},
},
});
44 changes: 44 additions & 0 deletions examples/client/reconnect/number/README.md
@@ -0,0 +1,44 @@
# client.reconnect Option

## number

Tells dev-server the number of times it should try to reconnect the client.

**webpack.config.js**

```js
module.exports = {
// ...
devServer: {
client: {
reconect: 2,
},
},
};
```

Usage via CLI:

```shell
npx webpack serve --open --client-reconnect 2
```

## What Should Happen

1. The script should open `http://localhost:8080/` in your default browser.
2. Open the console tab in your browser's devtools.
3. Now close the server with `Ctrl+C` to disconnect the client.

In the devtools console you should see that webpack-dev-server tried to reconnect the client 2 times:

```
[webpack-dev-server] Hot Module Replacement enabled.
[webpack-dev-server] Live Reloading enabled.
[webpack-dev-server] Disconnected!
[webpack-dev-server] Trying to reconnect...
WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
[webpack-dev-server] JSHandle@object
[webpack-dev-server] Trying to reconnect...
WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
[webpack-dev-server] JSHandle@object
```
7 changes: 7 additions & 0 deletions examples/client/reconnect/number/app.js
@@ -0,0 +1,7 @@
"use strict";

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

target.classList.add("pass");
target.innerHTML =
"Success! <br> Now, open the console tab in your browser's devtools. Then, close the server with `Ctrl+C` to disconnect the client.";
15 changes: 15 additions & 0 deletions examples/client/reconnect/number/webpack.config.js
@@ -0,0 +1,15 @@
"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",
devServer: {
client: {
reconnect: 2,
},
},
});
47 changes: 47 additions & 0 deletions examples/client/reconnect/true/README.md
@@ -0,0 +1,47 @@
# client.reconnect: true

## true

Tells dev-server the number of times it should try to reconnect the client. When `true` it will try to reconnect unlimited times.

**webpack.config.js**

```js
module.exports = {
// ...
devServer: {
client: {
reconect: true,
},
},
};
```

Usage via CLI:

```shell
npx webpack serve --open --client-reconnect
```

## What Should Happen

1. The script should open `http://localhost:8080/` in your default browser.
2. Open the console tab in your browser's devtools.
3. Now close the server with `Ctrl+C` to disconnect the client.

In the devtools console you should see that webpack-dev-server is trying to reconnect:

```
[webpack-dev-server] Hot Module Replacement enabled.
[webpack-dev-server] Live Reloading enabled.
[webpack-dev-server] Disconnected!
[webpack-dev-server] Trying to reconnect...
WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
[webpack-dev-server] JSHandle@object
[webpack-dev-server] Trying to reconnect...
WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
[webpack-dev-server] JSHandle@object
[webpack-dev-server] Trying to reconnect...
WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
[webpack-dev-server] JSHandle@object
```
7 changes: 7 additions & 0 deletions examples/client/reconnect/true/app.js
@@ -0,0 +1,7 @@
"use strict";

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

target.classList.add("pass");
target.innerHTML =
"Success! <br> Now, open the console tab in your browser's devtools. Then, close the server with `Ctrl+C` to disconnect the client.";
15 changes: 15 additions & 0 deletions examples/client/reconnect/true/webpack.config.js
@@ -0,0 +1,15 @@
"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",
devServer: {
client: {
reconnect: true,
},
},
});

0 comments on commit 0153c69

Please sign in to comment.