Skip to content

Commit 4f5bab1

Browse files
authored
docs: improve examples (#3672)
1 parent f2d87fb commit 4f5bab1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+480
-170
lines changed

examples/cli/bonjour/README.md renamed to examples/bonjour/README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
The Bonjour capability broadcasts server information via ZeroConf when the Server
44
is started.
55

6-
To run this example, run this command in your console or terminal:
6+
**webpack.config.js**
7+
8+
```js
9+
module.exports = {
10+
// ...
11+
devServer: {
12+
bonjour: true,
13+
},
14+
};
15+
```
16+
17+
Usage via CLI:
718

819
```console
920
npx webpack serve --bonjour
File renamed without changes.

examples/cli/hmr/webpack.config.js renamed to examples/bonjour/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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,

examples/cli/https/README.md

-31
This file was deleted.

examples/cli/https/webpack.config.js

-10
This file was deleted.

examples/cli/open-target/README.md

-34
This file was deleted.

examples/cli/progress/webpack.config.js

-10
This file was deleted.

examples/cli/web-socket-server/webpack.config.js

-10
This file was deleted.

examples/cli/web-socket-url-cli/README.md

-21
This file was deleted.

examples/cli/web-socket-url-cli/app.js

-6
This file was deleted.

examples/cli/web-socket-url-cli/webpack.config.js

-10
This file was deleted.

examples/cli/compression/README.md renamed to examples/compression/README.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ to roughly 30% of its original size before the files are sent to the browser.
55

66
It is enabled by default.
77

8-
## `--compress`
8+
## true
99

10-
To run this example, run this command in your console or terminal:
10+
**webpack.config.js**
11+
12+
```js
13+
module.exports = {
14+
// ...
15+
devServer: {
16+
compress: true,
17+
},
18+
};
19+
```
20+
21+
Usage via CLI:
1122

1223
```console
1324
npx webpack serve --open --compress
@@ -20,9 +31,20 @@ npx webpack serve --open --compress
2031
3. Open the console in your browser's devtools and select the _Network_ tab.
2132
4. Find `bundle.js`. The response headers should contain `Content-Encoding: gzip`.
2233

23-
## `--no-compress`
34+
## false
35+
36+
**webpack.config.js**
37+
38+
```js
39+
module.exports = {
40+
// ...
41+
devServer: {
42+
compress: false,
43+
},
44+
};
45+
```
2446

25-
To run this example, run this command in your console or terminal:
47+
Usage via CLI:
2648

2749
```console
2850
npx webpack serve --open --no-compress
File renamed without changes.

examples/cli/bonjour/webpack.config.js renamed to examples/compression/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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,

examples/cli/default/README.md renamed to examples/default/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CLI: Default State
1+
# Default State
22

33
This example demonstrates how to use `webpack-dev-server`.
44

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/cli/default/webpack.config.js renamed to examples/default/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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,

examples/cli/history-api-fallback/README.md renamed to examples/history-api-fallback/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
# CLI: History API Fallback Option
1+
# historyApiFallback Option
22

33
This option enables [History API Fallback](https://github.com/bripkens/connect-history-api-fallback)
44
support in `webpack-dev-server`, effectively asking the server to fallback to
55
`index.html` in the event that a requested resource cannot be found.
66

7-
```shell
7+
**webpack.config.js**
8+
9+
```js
10+
module.exports = {
11+
// ...
12+
devServer: {
13+
historyApiFallback: true,
14+
},
15+
};
16+
```
17+
18+
Usage via CLI:
19+
20+
```console
821
npx webpack serve --open --history-api-fallback
922
```
1023

examples/cli/history-api-fallback/webpack.config.js renamed to examples/history-api-fallback/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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,

examples/cli/hmr/README.md renamed to examples/hmr/README.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@
33
Hot Module Replacement (HMR) exchanges, adds, or removes modules while an
44
application is running, without a full reload of the page.
55

6-
## --hot
6+
## true
77

8-
To run this example, run this command in your console or terminal:
8+
Enable webpack's [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) feature:
9+
10+
**webpack.config.js**
11+
12+
```js
13+
module.exports = {
14+
// ...
15+
devServer: {
16+
hot: true,
17+
},
18+
};
19+
```
20+
21+
Usage via CLI:
922

1023
```console
1124
npx webpack serve --open --hot
@@ -31,10 +44,23 @@ In the devtools console you should see:
3144
You should also see the text on the page itself change to match your edits in
3245
`example.js`.
3346

34-
## --hot only
47+
## only
3548

3649
Enables Hot Module Replacement without page refresh as a fallback in case of build failures.
3750

51+
**webpack.config.js**
52+
53+
```js
54+
module.exports = {
55+
// ...
56+
devServer: {
57+
hot: "only",
58+
},
59+
};
60+
```
61+
62+
Usage via CLI:
63+
3864
```console
3965
npx webpack serve --open --hot only
4066
```
File renamed without changes.
File renamed without changes.

examples/cli/host-and-port/webpack.config.js renamed to examples/hmr/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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,

0 commit comments

Comments
 (0)