Skip to content

Commit 613487a

Browse files
author
jeromeh
committed
� Conflicts: � lib/utils/DevServerPlugin.js � test/server/utils/DevServerPlugin.test.js
2 parents 8845e26 + d3837f9 commit 613487a

33 files changed

+21688
-4388
lines changed

.github/workflows/nodejs.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,25 @@ jobs:
7878
if: matrix.os == 'windows-latest'
7979
run: npm i -g npm
8080

81+
- name: Get npm cache directory
82+
id: npm-cache-dir
83+
run: |
84+
echo "::set-output name=dir::$(npm config get cache)"
85+
8186
- name: Cache Node.js modules
8287
id: cache
8388
uses: actions/cache@v2
8489
with:
85-
# npm cache files are stored in `~/.npm` on Linux/macOS
86-
path: ~/.npm
87-
key: ${{ runner.OS }}-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
90+
path: ${{ steps.npm-cache-dir.outputs.dir }}
91+
key: ${{ runner.os }}-${{ matrix.webpack-version }}-node-${{ hashFiles('**/package-lock.json') }}
92+
restore-keys: |
93+
${{ runner.os }}-${{ matrix.webpack-version }}-node-
8894
8995
- name: Install dependencies
90-
if: steps.cache.outputs.cache-hit != 'true'
9196
run: npm ci
9297

9398
- name: Install webpack ${{ matrix.webpack-version }}
99+
if: matrix.webpack-version == '4'
94100
run: npm i webpack@${{ matrix.webpack-version }}
95101

96102
- name: Link webpack-dev-server

CODE_OF_CONDUCT.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Code of Conduct
2+
3+
At webpack and webpack/webpack-cli repository we follow the [JSFoundation Code of Conduct][1].
4+
Please adhere to the guidelines there and feel free to report any violation of them to the **@webpack/core-team**,
5+
**@webpack/dev-server-team**, or <[email protected]>.
6+
7+
[1]: https://github.com/openjs-foundation/code-and-learn/blob/main/CODE_OF_CONDUCT.md

CONTRIBUTING.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ Following these guidelines helps to communicate that you respect the time of the
1010

1111
- There are hooks to add your own features, so we should not add less-common features.
1212
- The workflow should be to start webpack-dev-server as a separate process, next to the "normal" server and to request the script from this server or to proxy from dev-server to "normal" server (because webpack blocks the event queue too much while compiling which can affect "normal" server).
13-
- A user should not try to implement stuff that accesses the webpack filesystem. This lead to bugs (the middleware does it while blocking requests until the compilation has finished, the blocking is important).
13+
- A user should not try to implement stuff that accesses the webpack filesystem. This leads to bugs (the middleware does it while blocking requests until the compilation has finished, the blocking is important).
1414
- It should be a development only tool. Compiling in production is bad, one should precompile and deliver the compiled assets.
1515
- Processing options and stats display is delegated to webpack, so webpack-dev-server/middleware should not do much with it. This also helps us to keep up-to-date with webpack updates.
1616
- The communication library (`SockJS`) should not be exposed to the user.
1717

1818
## Submitting a Pull Request
1919

20-
Good pull requests, such as patches, improvements, and new features, are a fantastic help. They should remain focused in scope and not contain unrelated commits.
20+
- Good pull requests, such as patches, improvements, and new features, are a fantastic help. They should remain focused in scope and not contain unrelated commits.
2121

22-
It is advised to first create an issue (if there is not one already) before making a pull request. This way the maintainers can first discuss with you if they agree and it also helps with providing some context.
22+
- It is advised to first create an issue (if there is not one already) before making a pull request. This way the maintainers can first discuss with you if they agree and it also helps with providing some context.
2323

24-
Run the relevant [examples](https://github.com/webpack/webpack-dev-server/tree/master/examples) to see if all functionality still works. When introducing new functionality, also add an example. This helps the maintainers to understand it and check if it still works.
24+
- Run the relevant [examples](https://github.com/webpack/webpack-dev-server/tree/master/examples) to see if all functionality still works. When introducing new functionality, also add an example. This helps the maintainers to understand it and check if it still works.
25+
26+
- Write tests.
27+
28+
- Follow the existing coding style.
29+
30+
- Make sure your PR's description contains GitHub's special keyword references that automatically close the related issue when the PR is merged. ([More info](https://github.com/blog/1506-closing-issues-via-pull-requests))
2531

2632
## Setting Up a Local Copy
2733

@@ -31,7 +37,7 @@ Run the relevant [examples](https://github.com/webpack/webpack-dev-server/tree/m
3137

3238
3. Run `npm link && npm link webpack-dev-server` to link the current project to `node_modules`.
3339

34-
Once it is done, you can modify any file locally. In the `examples/` directory you'll find a lot of examples with instructions on how to run it. This can be very handy when testing if your code works.
40+
Once it is done, you can modify any file locally. In the `examples/` directory you'll find a lot of examples with instructions on how to run them. This can be very handy when testing if your code works.
3541

3642
If you are modifying a file in the `client/` directory, be sure to run `npm run build:client` after it. This will recompile the files.
3743

README.md

+55-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,60 @@ The easiest way to use it is with the [webpack CLI](https://webpack.js.org/api/c
5858
node_modules/.bin/webpack serve
5959
```
6060

61-
_**Note**: Many CLI options are available with `webpack serve`. Explore this [link](https://webpack.js.org/configuration/dev-server/)._
61+
Following options are available with `webpack serve`:
62+
63+
```
64+
Usage: webpack serve|s [entries...] [options]
65+
66+
Options:
67+
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
68+
--config-name <value...> Name of the configuration to use.
69+
-m, --merge Merge two or more configurations using 'webpack-merge'.
70+
--env <value...> Environment passed to the configuration when it is a function.
71+
--progress [value] Print compilation progress during build.
72+
-j, --json [value] Prints result as JSON or store it in a file.
73+
-d, --devtool <value> Determine source maps to use.
74+
--no-devtool Do not generate source maps.
75+
--entry <value...> The entry point(s) of your application e.g. ./src/main.js.
76+
--mode <value> Defines the mode to pass to webpack.
77+
--name <value> Name of the configuration. Used when loading multiple configurations.
78+
-o, --output-path <value> Output location of the file generated by webpack e.g. ./dist/.
79+
--stats [value] It instructs webpack on how to treat the stats e.g. verbose.
80+
--no-stats Disable stats output.
81+
-t, --target <value...> Sets the build target e.g. node.
82+
--watch-options-stdin Stop watching when stdin stream has ended.
83+
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
84+
--host <value> The hostname/ip address the server will bind to.
85+
--port <value> The port server will listen to.
86+
--static [value...] A directory to serve static content from.
87+
--no-static Negative 'static' option.
88+
--live-reload Enables live reloading on changing files.
89+
--no-live-reload Disables live reloading on changing files.
90+
--https Use HTTPS protocol.
91+
--http2 Use HTTP/2, must be used with HTTPS.
92+
--bonjour Broadcasts the server via ZeroConf networking on start.
93+
--client-progress Print compilation progress in percentage in the browser.
94+
--hot-only Do not refresh page if HMR fails.
95+
--setup-exit-signals Close and exit the process on SIGINT and SIGTERM.
96+
--no-setup-exit-signals Do not close and exit the process on SIGNIT and SIGTERM.
97+
--stdin Close when stdin ends.
98+
--open [value] Open the default browser, or optionally specify a browser name.
99+
--use-local-ip Open default browser with local IP.
100+
--open-page <value...> Open default browser with the specified page.
101+
--client-logging <value> Log level in the browser (none, error, warn, info, log, verbose).
102+
--history-api-fallback Fallback to /index.html for Single Page Applications.
103+
--compress Enable gzip compression.
104+
--public <value> The public hostname/ip address of the server.
105+
--firewall <value...> Enable/disable firewall, or set hosts that are allowed to access the dev server.
106+
107+
Global options:
108+
--color Enable colors on console.
109+
--no-color Disable colors on console.
110+
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
111+
-h, --help [verbose] Display help for commands and options.
112+
```
113+
114+
_**Note**: For more information on above options explore this [link](https://webpack.js.org/configuration/dev-server/)._
62115

63116
### With NPM Scripts
64117

@@ -108,7 +161,7 @@ needed modifications to the code for the module. Because of that, we ask users
108161
with general support, "how-to", or "why isn't this working" questions to try one
109162
of the other support channels that are available.
110163

111-
Your first-stop-shop for support for webpack-dev-server should by the excellent
164+
Your first-stop-shop for support for webpack-dev-server should be the excellent
112165
[documentation][docs-url] for the module. If you see an opportunity for improvement
113166
of those docs, please head over to the [webpack.js.org repo][wjo-url] and open a
114167
pull request.

bin/cli-flags.js

+20-17
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module.exports = {
55
{
66
name: 'host',
77
type: String,
8-
description: 'The hostname/ip address the server will bind to',
8+
description: 'The hostname/ip address the server will bind to.',
99
},
1010
{
1111
name: 'port',
1212
type: Number,
13-
description: 'The port',
13+
description: 'The port server will listen to.',
1414
},
1515
{
1616
name: 'static',
@@ -22,28 +22,29 @@ module.exports = {
2222
{
2323
name: 'live-reload',
2424
type: Boolean,
25-
description: 'Enables/Disables live reloading on changing files',
25+
description: 'Enables live reloading on changing files.',
26+
negatedDescription: 'Disables live reloading on changing files.',
2627
negative: true,
2728
},
2829
{
2930
name: 'https',
3031
type: Boolean,
31-
description: 'HTTPS',
32+
description: 'Use HTTPS protocol.',
3233
},
3334
{
3435
name: 'http2',
3536
type: Boolean,
36-
description: 'HTTP/2, must be used with HTTPS',
37+
description: 'Use HTTP/2, must be used with HTTPS.',
3738
},
3839
{
3940
name: 'bonjour',
4041
type: Boolean,
41-
description: 'Broadcasts the server via ZeroConf networking on start',
42+
description: 'Broadcasts the server via ZeroConf networking on start.',
4243
},
4344
{
4445
name: 'client-progress',
4546
type: Boolean,
46-
description: 'Print compilation progress in percentage in the browser',
47+
description: 'Print compilation progress in percentage in the browser.',
4748
processor(opts) {
4849
opts.client = opts.client || {};
4950
opts.client.progress = opts.clientProgress;
@@ -53,7 +54,7 @@ module.exports = {
5354
{
5455
name: 'hot-only',
5556
type: Boolean,
56-
description: 'Do not refresh page if HMR fails',
57+
description: 'Do not refresh page if HMR fails.',
5758
processor(opts) {
5859
opts.hot = 'only';
5960
delete opts.hotOnly;
@@ -62,36 +63,38 @@ module.exports = {
6263
{
6364
name: 'setup-exit-signals',
6465
type: Boolean,
65-
description: 'Close and exit the process on SIGINT and SIGTERM',
66+
description: 'Close and exit the process on SIGINT and SIGTERM.',
67+
negatedDescription:
68+
'Do not close and exit the process on SIGNIT and SIGTERM.',
6669
negative: true,
6770
},
6871
{
6972
name: 'stdin',
7073
type: Boolean,
71-
description: 'close when stdin ends',
74+
description: 'Close when stdin ends.',
7275
},
7376
{
7477
name: 'open',
7578
type: [String, Boolean],
7679
description:
77-
'Open the default browser, or optionally specify a browser name',
80+
'Open the default browser, or optionally specify a browser name.',
7881
},
7982
{
8083
name: 'use-local-ip',
8184
type: Boolean,
82-
description: 'Open default browser with local IP',
85+
description: 'Open default browser with local IP.',
8386
},
8487
{
8588
name: 'open-page',
8689
type: String,
87-
description: 'Open default browser with the specified page',
90+
description: 'Open default browser with the specified page.',
8891
multiple: true,
8992
},
9093
{
9194
name: 'client-logging',
9295
type: String,
9396
description:
94-
'Log level in the browser (none, error, warn, info, log, verbose)',
97+
'Log level in the browser (none, error, warn, info, log, verbose).',
9598
processor(opts) {
9699
opts.client = opts.client || {};
97100
opts.client.logging = opts.clientLogging;
@@ -106,18 +109,18 @@ module.exports = {
106109
{
107110
name: 'compress',
108111
type: Boolean,
109-
description: 'Enable gzip compression',
112+
description: 'Enable gzip compression.',
110113
},
111114
{
112115
name: 'public',
113116
type: String,
114-
description: 'The public hostname/ip address of the server',
117+
description: 'The public hostname/ip address of the server.',
115118
},
116119
{
117120
name: 'firewall',
118121
type: String,
119122
description:
120-
'Enable/disable firewall, or set hosts that are allowed to access the dev server',
123+
'Enable/disable firewall, or set hosts that are allowed to access the dev server.',
121124
multiple: true,
122125
},
123126
],

client-src/default/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ const onSocketMessage = {
125125
},
126126
errors(errors) {
127127
log.error('Errors while compiling. Reload prevented.');
128-
const strippedErrors = errors.map((error) => stripAnsi(error));
128+
const strippedErrors = errors.map((error) =>
129+
stripAnsi(error.message ? error.message : error)
130+
);
129131
sendMessage('Errors', strippedErrors);
130132
for (let i = 0; i < strippedErrors.length; i++) {
131133
log.error(strippedErrors[i]);

client-src/default/utils/createSocketUrl.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,21 @@ function getSocketUrl(urlParts, loc) {
7272
// all of these sock url params are optionally passed in through
7373
// resourceQuery, so we need to fall back to the default if
7474
// they are not provided
75-
const host = query.host || hostname;
75+
let host = query.host || hostname;
7676
const path = query.path || '/ws';
7777
let portOption = query.port || port;
7878

7979
if (portOption === 'location') {
8080
portOption = loc.port;
8181
}
8282

83+
// In case the host is a raw IPv6 address, it can be enclosed in
84+
// the brackets as the brackets are needed in the final URL string.
85+
// Need to remove those as url.format blindly adds its own set of brackets
86+
// if the host string contains colons. That would lead to non-working
87+
// double brackets (e.g. [[::]]) host
88+
host = typeof host === 'string' ? host.replace(/^\[(.*)\]$/, '$1') : host;
89+
8390
return url.format({
8491
protocol,
8592
auth,

lib/Server.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const setupExitSignals = require('./utils/setupExitSignals');
3434
const findPort = require('./utils/findPort');
3535
const schema = require('./options.json');
3636

37-
if (!process.env.WEBPACK_DEV_SERVER) {
38-
process.env.WEBPACK_DEV_SERVER = true;
37+
if (!process.env.WEBPACK_SERVE) {
38+
process.env.WEBPACK_SERVE = true;
3939
}
4040

4141
class Server {
@@ -588,14 +588,14 @@ class Server {
588588
const useColor = getColorsOption(getCompilerConfigArray(this.compiler));
589589

590590
const protocol = this.options.https ? 'https' : 'http';
591-
const { hostname, port } = this;
591+
const { address: hostname, port } = this.server.address();
592592
const prettyPrintUrl = (newHostname) =>
593593
url.format({ protocol, hostname: newHostname, port, pathname: '/' });
594594

595595
let prettyHostname;
596596
let lanUrlForTerminal;
597597

598-
if (hostname === '0.0.0.0' || hostname === '::') {
598+
if (hostname === '0.0.0.0' || ip.isLoopback(hostname)) {
599599
prettyHostname = 'localhost';
600600

601601
const localIP =
@@ -662,7 +662,7 @@ class Server {
662662
);
663663
}
664664

665-
if (this.options.open) {
665+
if (this.options.open || this.options.openPage) {
666666
runOpen(localUrlForTerminal, this.options, this.logger);
667667
}
668668
}

0 commit comments

Comments
 (0)