Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add examples for the client.reconnect option #3938

Merged
merged 1 commit into from
Oct 12, 2021
Merged
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
38 changes: 38 additions & 0 deletions examples/client/reconnect/false/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
},
},
});