Skip to content

Commit ccb6f76

Browse files
authored
docs: improve webSocketServer example (#3886)
1 parent 1b6e242 commit ccb6f76

File tree

6 files changed

+53
-23
lines changed

6 files changed

+53
-23
lines changed

examples/web-socket-server/README.md renamed to examples/web-socket-server/sockjs/README.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# web-socket-server
1+
# web-socket-server (sockjs)
22

33
To create a custom server implementation.
44

@@ -23,27 +23,6 @@ Usage via CLI:
2323
npx webpack serve --web-socket-server sockjs --open
2424
```
2525

26-
## ws
27-
28-
This mode uses [ws](https://github.com/websockets/ws) as a server.
29-
30-
**webpack.config.js**
31-
32-
```js
33-
module.exports = {
34-
// ...
35-
devServer: {
36-
webSocketServer: "ws",
37-
},
38-
};
39-
```
40-
41-
Usage via CLI:
42-
43-
```console
44-
npx webpack serve --web-socket-server ws --open
45-
```
46-
4726
### What Should Happen
4827

4928
1. The script should open `http://localhost:8080/` in your default browser.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
// our setup function adds behind-the-scenes bits to the config that all of our
4+
// examples need
5+
const { setup } = require("../../util");
6+
7+
module.exports = setup({
8+
context: __dirname,
9+
entry: "./app.js",
10+
devServer: {
11+
webSocketServer: "sockjs",
12+
},
13+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# web-socket-server (ws)
2+
3+
To create a custom server implementation.
4+
5+
## ws
6+
7+
This mode uses [ws](https://github.com/websockets/ws) as a server.
8+
9+
**webpack.config.js**
10+
11+
```js
12+
module.exports = {
13+
// ...
14+
devServer: {
15+
webSocketServer: "ws",
16+
},
17+
};
18+
```
19+
20+
Usage via CLI:
21+
22+
```console
23+
npx webpack serve --web-socket-server ws --open
24+
```
25+
26+
### What Should Happen
27+
28+
1. The script should open `http://localhost:8080/` in your default browser.
29+
2. You should see the text on the page itself change to read `Success!`.

examples/web-socket-server/ws/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
const target = document.querySelector("#target");
4+
5+
target.classList.add("pass");
6+
target.innerHTML = "Success!";

examples/web-socket-server/webpack.config.js renamed to examples/web-socket-server/ws/webpack.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

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

77
module.exports = setup({
88
context: __dirname,
99
entry: "./app.js",
10+
devServer: {
11+
webSocketServer: "ws",
12+
},
1013
});

0 commit comments

Comments
 (0)