webpack-dev-server 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/index.js +21 -13
- package/client/overlay.js +30 -5
- package/lib/Server.js +67 -38
- package/lib/options.json +27 -1
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import webpackHotLog from "webpack/hot/log.js";
|
|
|
3
3
|
import stripAnsi from "./modules/strip-ansi/index.js";
|
|
4
4
|
import parseURL from "./utils/parseURL.js";
|
|
5
5
|
import socket from "./socket.js";
|
|
6
|
-
import { show, hide } from "./overlay.js";
|
|
6
|
+
import { formatProblem, show, hide } from "./overlay.js";
|
|
7
7
|
import { log, setLogLevel } from "./utils/log.js";
|
|
8
8
|
import sendMessage from "./utils/sendMessage.js";
|
|
9
9
|
import reloadApp from "./utils/reloadApp.js";
|
|
@@ -128,20 +128,24 @@ var onSocketMessage = {
|
|
|
128
128
|
warnings: function warnings(_warnings) {
|
|
129
129
|
log.warn("Warnings while compiling.");
|
|
130
130
|
|
|
131
|
-
var
|
|
132
|
-
|
|
131
|
+
var printableWarnings = _warnings.map(function (error) {
|
|
132
|
+
var _formatProblem = formatProblem("warning", error),
|
|
133
|
+
header = _formatProblem.header,
|
|
134
|
+
body = _formatProblem.body;
|
|
135
|
+
|
|
136
|
+
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
133
137
|
});
|
|
134
138
|
|
|
135
|
-
sendMessage("Warnings",
|
|
139
|
+
sendMessage("Warnings", printableWarnings);
|
|
136
140
|
|
|
137
|
-
for (var i = 0; i <
|
|
138
|
-
log.warn(
|
|
141
|
+
for (var i = 0; i < printableWarnings.length; i++) {
|
|
142
|
+
log.warn(printableWarnings[i]);
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
var needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings;
|
|
142
146
|
|
|
143
147
|
if (needShowOverlayForWarnings) {
|
|
144
|
-
show(
|
|
148
|
+
show("warning", _warnings);
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
reloadApp(options, status);
|
|
@@ -149,20 +153,24 @@ var onSocketMessage = {
|
|
|
149
153
|
errors: function errors(_errors) {
|
|
150
154
|
log.error("Errors while compiling. Reload prevented.");
|
|
151
155
|
|
|
152
|
-
var
|
|
153
|
-
|
|
156
|
+
var printableErrors = _errors.map(function (error) {
|
|
157
|
+
var _formatProblem2 = formatProblem("error", error),
|
|
158
|
+
header = _formatProblem2.header,
|
|
159
|
+
body = _formatProblem2.body;
|
|
160
|
+
|
|
161
|
+
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
154
162
|
});
|
|
155
163
|
|
|
156
|
-
sendMessage("Errors",
|
|
164
|
+
sendMessage("Errors", printableErrors);
|
|
157
165
|
|
|
158
|
-
for (var i = 0; i <
|
|
159
|
-
log.error(
|
|
166
|
+
for (var i = 0; i < printableErrors.length; i++) {
|
|
167
|
+
log.error(printableErrors[i]);
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
var needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors;
|
|
163
171
|
|
|
164
172
|
if (needShowOverlayForErrors) {
|
|
165
|
-
show(
|
|
173
|
+
show("error", _errors);
|
|
166
174
|
}
|
|
167
175
|
},
|
|
168
176
|
error: function error(_error) {
|
package/client/overlay.js
CHANGED
|
@@ -108,19 +108,44 @@ function hide() {
|
|
|
108
108
|
document.body.removeChild(iframeContainerElement);
|
|
109
109
|
iframeContainerElement = null;
|
|
110
110
|
containerElement = null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function formatProblem(type, item) {
|
|
114
|
+
var header = type === "warning" ? "WARNING" : "ERROR";
|
|
115
|
+
var body = "";
|
|
116
|
+
|
|
117
|
+
if (typeof item === "string") {
|
|
118
|
+
body += item;
|
|
119
|
+
} else {
|
|
120
|
+
var file = item.file || ""; // eslint-disable-next-line no-nested-ternary
|
|
121
|
+
|
|
122
|
+
var moduleName = item.moduleName ? item.moduleName.indexOf("!") !== -1 ? "".concat(item.moduleName.replace(/^(\s|\S)*!/, ""), " (").concat(item.moduleName, ")") : "".concat(item.moduleName) : "";
|
|
123
|
+
var loc = item.loc;
|
|
124
|
+
header += "".concat(moduleName || file ? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : "") : file).concat(loc ? " ".concat(loc) : "") : "");
|
|
125
|
+
body += item.message || "";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
header: header,
|
|
130
|
+
body: body
|
|
131
|
+
};
|
|
111
132
|
} // Compilation with errors (e.g. syntax error or missing modules).
|
|
112
133
|
|
|
113
134
|
|
|
114
|
-
function show(
|
|
135
|
+
function show(type, messages) {
|
|
115
136
|
ensureOverlayExists(function () {
|
|
116
137
|
messages.forEach(function (message) {
|
|
117
138
|
var entryElement = document.createElement("div");
|
|
118
139
|
var typeElement = document.createElement("span");
|
|
119
|
-
|
|
140
|
+
|
|
141
|
+
var _formatProblem = formatProblem(type, message),
|
|
142
|
+
header = _formatProblem.header,
|
|
143
|
+
body = _formatProblem.body;
|
|
144
|
+
|
|
145
|
+
typeElement.innerText = header;
|
|
120
146
|
typeElement.style.color = "#".concat(colors.red); // Make it look similar to our terminal.
|
|
121
147
|
|
|
122
|
-
var
|
|
123
|
-
var text = ansiHTML(encode(errorMessage));
|
|
148
|
+
var text = ansiHTML(encode(body));
|
|
124
149
|
var messageTextNode = document.createElement("div");
|
|
125
150
|
messageTextNode.innerHTML = text;
|
|
126
151
|
entryElement.appendChild(typeElement);
|
|
@@ -134,4 +159,4 @@ function show(messages, type) {
|
|
|
134
159
|
});
|
|
135
160
|
}
|
|
136
161
|
|
|
137
|
-
export { show, hide };
|
|
162
|
+
export { formatProblem, show, hide };
|
package/lib/Server.js
CHANGED
|
@@ -74,7 +74,7 @@ class Server {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
static async getFreePort(port) {
|
|
77
|
-
if (port && port !== "auto") {
|
|
77
|
+
if (typeof port !== "undefined" && port !== null && port !== "auto") {
|
|
78
78
|
return port;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -1063,42 +1063,43 @@ class Server {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
|
|
1065
1065
|
async initialize() {
|
|
1066
|
-
|
|
1066
|
+
if (this.options.webSocketServer) {
|
|
1067
|
+
const compilers = this.compiler.compilers || [this.compiler];
|
|
1067
1068
|
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1069
|
+
// eslint-disable-next-line no-shadow
|
|
1070
|
+
compilers.forEach((compiler) => {
|
|
1071
|
+
this.addAdditionalEntries(compiler);
|
|
1071
1072
|
|
|
1072
|
-
|
|
1073
|
+
const webpack = compiler.webpack || require("webpack");
|
|
1073
1074
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1075
|
+
new webpack.ProvidePlugin({
|
|
1076
|
+
__webpack_dev_server_client__: this.getClientTransport(),
|
|
1077
|
+
}).apply(compiler);
|
|
1077
1078
|
|
|
1078
|
-
|
|
1079
|
+
// TODO remove after drop webpack v4 support
|
|
1080
|
+
compiler.options.plugins = compiler.options.plugins || [];
|
|
1079
1081
|
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
+
if (this.options.hot) {
|
|
1083
|
+
const HMRPluginExists = compiler.options.plugins.find(
|
|
1084
|
+
(p) => p.constructor === webpack.HotModuleReplacementPlugin
|
|
1085
|
+
);
|
|
1082
1086
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
+
if (HMRPluginExists) {
|
|
1088
|
+
this.logger.warn(
|
|
1089
|
+
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
|
|
1090
|
+
);
|
|
1091
|
+
} else {
|
|
1092
|
+
// Apply the HMR plugin
|
|
1093
|
+
const plugin = new webpack.HotModuleReplacementPlugin();
|
|
1087
1094
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
|
|
1091
|
-
);
|
|
1092
|
-
} else {
|
|
1093
|
-
// apply the HMR plugin
|
|
1094
|
-
const plugin = new webpack.HotModuleReplacementPlugin();
|
|
1095
|
-
plugin.apply(compiler);
|
|
1095
|
+
plugin.apply(compiler);
|
|
1096
|
+
}
|
|
1096
1097
|
}
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1098
|
+
});
|
|
1099
1099
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1100
|
+
if (this.options.client && this.options.client.progress) {
|
|
1101
|
+
this.setupProgressPlugin();
|
|
1102
|
+
}
|
|
1102
1103
|
}
|
|
1103
1104
|
|
|
1104
1105
|
this.setupHooks();
|
|
@@ -1114,11 +1115,31 @@ class Server {
|
|
|
1114
1115
|
if (this.options.setupExitSignals) {
|
|
1115
1116
|
const signals = ["SIGINT", "SIGTERM"];
|
|
1116
1117
|
|
|
1118
|
+
let needForceShutdown = false;
|
|
1119
|
+
|
|
1120
|
+
const exitProcess = () => {
|
|
1121
|
+
// eslint-disable-next-line no-process-exit
|
|
1122
|
+
process.exit();
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1117
1125
|
signals.forEach((signal) => {
|
|
1118
1126
|
process.on(signal, () => {
|
|
1127
|
+
if (needForceShutdown) {
|
|
1128
|
+
exitProcess();
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
this.logger.info(
|
|
1132
|
+
"Gracefully shutting down. To force exit, press ^C again. Please wait..."
|
|
1133
|
+
);
|
|
1134
|
+
|
|
1135
|
+
needForceShutdown = true;
|
|
1136
|
+
|
|
1119
1137
|
this.stopCallback(() => {
|
|
1120
|
-
|
|
1121
|
-
|
|
1138
|
+
if (typeof this.compiler.close === "function") {
|
|
1139
|
+
this.compiler.close(exitProcess);
|
|
1140
|
+
} else {
|
|
1141
|
+
exitProcess();
|
|
1142
|
+
}
|
|
1122
1143
|
});
|
|
1123
1144
|
});
|
|
1124
1145
|
});
|
|
@@ -1672,7 +1693,7 @@ class Server {
|
|
|
1672
1693
|
}
|
|
1673
1694
|
|
|
1674
1695
|
logStatus() {
|
|
1675
|
-
const
|
|
1696
|
+
const { isColorSupported, cyan, red } = require("colorette");
|
|
1676
1697
|
|
|
1677
1698
|
const getColorsOption = (compilerOptions) => {
|
|
1678
1699
|
let colorsEnabled;
|
|
@@ -1683,7 +1704,7 @@ class Server {
|
|
|
1683
1704
|
) {
|
|
1684
1705
|
colorsEnabled = compilerOptions.stats;
|
|
1685
1706
|
} else {
|
|
1686
|
-
colorsEnabled =
|
|
1707
|
+
colorsEnabled = isColorSupported;
|
|
1687
1708
|
}
|
|
1688
1709
|
|
|
1689
1710
|
return colorsEnabled;
|
|
@@ -1692,14 +1713,14 @@ class Server {
|
|
|
1692
1713
|
const colors = {
|
|
1693
1714
|
info(useColor, msg) {
|
|
1694
1715
|
if (useColor) {
|
|
1695
|
-
return
|
|
1716
|
+
return cyan(msg);
|
|
1696
1717
|
}
|
|
1697
1718
|
|
|
1698
1719
|
return msg;
|
|
1699
1720
|
},
|
|
1700
1721
|
error(useColor, msg) {
|
|
1701
1722
|
if (useColor) {
|
|
1702
|
-
return
|
|
1723
|
+
return red(msg);
|
|
1703
1724
|
}
|
|
1704
1725
|
|
|
1705
1726
|
return msg;
|
|
@@ -1845,10 +1866,19 @@ class Server {
|
|
|
1845
1866
|
headers = headers(req, res, this.middleware.context);
|
|
1846
1867
|
}
|
|
1847
1868
|
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1869
|
+
const allHeaders = [];
|
|
1870
|
+
|
|
1871
|
+
if (!Array.isArray(headers)) {
|
|
1872
|
+
// eslint-disable-next-line guard-for-in
|
|
1873
|
+
for (const name in headers) {
|
|
1874
|
+
allHeaders.push({ key: name, value: headers[name] });
|
|
1875
|
+
}
|
|
1876
|
+
headers = allHeaders;
|
|
1851
1877
|
}
|
|
1878
|
+
|
|
1879
|
+
headers.forEach((header) => {
|
|
1880
|
+
res.setHeader(header.key, header.value);
|
|
1881
|
+
});
|
|
1852
1882
|
}
|
|
1853
1883
|
|
|
1854
1884
|
next();
|
|
@@ -2036,7 +2066,6 @@ class Server {
|
|
|
2036
2066
|
};
|
|
2037
2067
|
|
|
2038
2068
|
const chokidar = require("chokidar");
|
|
2039
|
-
|
|
2040
2069
|
const watcher = chokidar.watch(watchPath, finalWatchOptions);
|
|
2041
2070
|
|
|
2042
2071
|
// disabling refreshing on changing the content
|
package/lib/options.json
CHANGED
|
@@ -369,8 +369,32 @@
|
|
|
369
369
|
"description": "Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
370
370
|
"link": "https://webpack.js.org/configuration/dev-server/#devserverhttps"
|
|
371
371
|
},
|
|
372
|
+
"HeaderObject": {
|
|
373
|
+
"type": "object",
|
|
374
|
+
"additionalProperties": false,
|
|
375
|
+
"properties": {
|
|
376
|
+
"key": {
|
|
377
|
+
"description": "key of header.",
|
|
378
|
+
"type": "string"
|
|
379
|
+
},
|
|
380
|
+
"value": {
|
|
381
|
+
"description": "value of header.",
|
|
382
|
+
"type": "string"
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
"cli": {
|
|
386
|
+
"exclude": true
|
|
387
|
+
}
|
|
388
|
+
},
|
|
372
389
|
"Headers": {
|
|
373
390
|
"anyOf": [
|
|
391
|
+
{
|
|
392
|
+
"type": "array",
|
|
393
|
+
"items": {
|
|
394
|
+
"$ref": "#/definitions/HeaderObject"
|
|
395
|
+
},
|
|
396
|
+
"minItems": 1
|
|
397
|
+
},
|
|
374
398
|
{
|
|
375
399
|
"type": "object"
|
|
376
400
|
},
|
|
@@ -554,7 +578,9 @@
|
|
|
554
578
|
"Port": {
|
|
555
579
|
"anyOf": [
|
|
556
580
|
{
|
|
557
|
-
"type": "number"
|
|
581
|
+
"type": "number",
|
|
582
|
+
"minimum": 0,
|
|
583
|
+
"maximum": 65535
|
|
558
584
|
},
|
|
559
585
|
{
|
|
560
586
|
"type": "string",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-dev-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Serves a webpack app. Updates the browser on changes.",
|
|
5
5
|
"bin": "bin/webpack-dev-server.js",
|
|
6
6
|
"main": "lib/Server.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"ansi-html-community": "^0.0.8",
|
|
36
36
|
"bonjour": "^3.5.0",
|
|
37
37
|
"chokidar": "^3.5.1",
|
|
38
|
-
"colorette": "^
|
|
38
|
+
"colorette": "^2.0.10",
|
|
39
39
|
"compression": "^1.7.4",
|
|
40
40
|
"connect-history-api-fallback": "^1.6.0",
|
|
41
41
|
"del": "^6.0.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"spdy": "^4.0.2",
|
|
56
56
|
"strip-ansi": "^7.0.0",
|
|
57
57
|
"url": "^0.11.0",
|
|
58
|
-
"webpack-dev-middleware": "^5.1
|
|
58
|
+
"webpack-dev-middleware": "^5.2.1",
|
|
59
59
|
"ws": "^8.1.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"tcp-port-used": "^1.0.2",
|
|
104
104
|
"typescript": "^4.2.4",
|
|
105
105
|
"url-loader": "^4.1.1",
|
|
106
|
-
"webpack": "^5.
|
|
106
|
+
"webpack": "^5.54.0",
|
|
107
107
|
"webpack-cli": "^4.7.2",
|
|
108
108
|
"webpack-merge": "^5.8.0"
|
|
109
109
|
},
|