webpack-dev-server 3.5.1 → 3.7.2
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/CHANGELOG.md +45 -0
- package/client/clients/BaseClient.js +27 -0
- package/client/clients/SockJSClient.js +69 -0
- package/client/clients/WebsocketClient.js +31 -0
- package/client/index.bundle.js +1 -1
- package/client/index.js +9 -110
- package/client/live.bundle.js +3 -3
- package/client/overlay.js +19 -22
- package/client/socket.js +24 -17
- package/client/utils/createSocketUrl.js +78 -0
- package/client/utils/log.js +49 -0
- package/client/utils/reloadApp.js +2 -1
- package/lib/Server.js +23 -11
- package/lib/options.json +14 -3
- package/lib/utils/createConfig.js +4 -0
- package/lib/utils/createLogger.js +1 -1
- package/lib/utils/findPort.js +17 -6
- package/lib/utils/getSocketServerImplementation.js +41 -0
- package/lib/utils/runOpen.js +4 -3
- package/lib/utils/tryParseInt.js +2 -0
- package/lib/utils/updateCompiler.js +8 -0
- package/package.json +22 -18
package/client/index.js
CHANGED
|
@@ -3,25 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
/* eslint prefer-destructuring: off */
|
|
5
5
|
|
|
6
|
-
var querystring = require('querystring');
|
|
7
|
-
|
|
8
|
-
var url = require('url');
|
|
9
|
-
|
|
10
6
|
var stripAnsi = require('strip-ansi');
|
|
11
7
|
|
|
12
|
-
var log = require('loglevel').getLogger('webpack-dev-server');
|
|
13
|
-
|
|
14
8
|
var socket = require('./socket');
|
|
15
9
|
|
|
16
10
|
var overlay = require('./overlay');
|
|
17
11
|
|
|
12
|
+
var _require = require('./utils/log'),
|
|
13
|
+
log = _require.log,
|
|
14
|
+
setLogLevel = _require.setLogLevel;
|
|
15
|
+
|
|
18
16
|
var sendMessage = require('./utils/sendMessage');
|
|
19
17
|
|
|
20
18
|
var reloadApp = require('./utils/reloadApp');
|
|
21
19
|
|
|
22
|
-
var
|
|
20
|
+
var createSocketUrl = require('./utils/createSocketUrl');
|
|
23
21
|
|
|
24
|
-
var urlParts;
|
|
25
22
|
var status = {
|
|
26
23
|
isUnloading: false,
|
|
27
24
|
currentHash: ''
|
|
@@ -35,6 +32,7 @@ var options = {
|
|
|
35
32
|
useErrorOverlay: false,
|
|
36
33
|
useProgress: false
|
|
37
34
|
};
|
|
35
|
+
var socketUrl = createSocketUrl(__resourceQuery);
|
|
38
36
|
self.addEventListener('beforeunload', function () {
|
|
39
37
|
status.isUnloading = true;
|
|
40
38
|
});
|
|
@@ -44,35 +42,7 @@ if (typeof window !== 'undefined') {
|
|
|
44
42
|
options.hotReload = qs.indexOf('hotreload=false') === -1;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
// If this bundle is inlined, use the resource query to get the correct url.
|
|
49
|
-
urlParts = url.parse(__resourceQuery.substr(1));
|
|
50
|
-
} else {
|
|
51
|
-
// Else, get the url from the <script> this file was called with.
|
|
52
|
-
var scriptHost = getCurrentScriptSource(); // eslint-disable-next-line no-useless-escape
|
|
53
|
-
|
|
54
|
-
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
|
|
55
|
-
urlParts = url.parse(scriptHost || '/', false, true);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!urlParts.port || urlParts.port === '0') {
|
|
59
|
-
urlParts.port = self.location.port;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var INFO = 'info';
|
|
63
|
-
var WARN = 'warn';
|
|
64
|
-
var ERROR = 'error';
|
|
65
|
-
var DEBUG = 'debug';
|
|
66
|
-
var TRACE = 'trace';
|
|
67
|
-
var SILENT = 'silent'; // deprecated
|
|
68
|
-
// TODO: remove these at major released
|
|
69
|
-
// https://github.com/webpack/webpack-dev-server/pull/1825
|
|
70
|
-
|
|
71
|
-
var WARNING = 'warning';
|
|
72
|
-
var NONE = 'none'; // Set the default log level
|
|
73
|
-
|
|
74
|
-
log.setDefaultLevel(INFO);
|
|
75
|
-
var onSocketMsg = {
|
|
45
|
+
var onSocketMessage = {
|
|
76
46
|
hot: function hot() {
|
|
77
47
|
options.hot = true;
|
|
78
48
|
log.info('[WDS] Hot Module Replacement enabled.');
|
|
@@ -109,30 +79,7 @@ var onSocketMsg = {
|
|
|
109
79
|
hotCtx('./log').setLogLevel(level);
|
|
110
80
|
}
|
|
111
81
|
|
|
112
|
-
|
|
113
|
-
case INFO:
|
|
114
|
-
case WARN:
|
|
115
|
-
case DEBUG:
|
|
116
|
-
case TRACE:
|
|
117
|
-
case ERROR:
|
|
118
|
-
log.setLevel(level);
|
|
119
|
-
break;
|
|
120
|
-
// deprecated
|
|
121
|
-
|
|
122
|
-
case WARNING:
|
|
123
|
-
// loglevel's warning name is different from webpack's
|
|
124
|
-
log.setLevel('warn');
|
|
125
|
-
break;
|
|
126
|
-
// deprecated
|
|
127
|
-
|
|
128
|
-
case NONE:
|
|
129
|
-
case SILENT:
|
|
130
|
-
log.disableAll();
|
|
131
|
-
break;
|
|
132
|
-
|
|
133
|
-
default:
|
|
134
|
-
log.error("[WDS] Unknown clientLogLevel '".concat(level, "'"));
|
|
135
|
-
}
|
|
82
|
+
setLogLevel(level);
|
|
136
83
|
},
|
|
137
84
|
overlay: function overlay(value) {
|
|
138
85
|
if (typeof document !== 'undefined') {
|
|
@@ -226,52 +173,4 @@ var onSocketMsg = {
|
|
|
226
173
|
sendMessage('Close');
|
|
227
174
|
}
|
|
228
175
|
};
|
|
229
|
-
|
|
230
|
-
hostname = _urlParts.hostname,
|
|
231
|
-
protocol = _urlParts.protocol; // check ipv4 and ipv6 `all hostname`
|
|
232
|
-
|
|
233
|
-
if (hostname === '0.0.0.0' || hostname === '::') {
|
|
234
|
-
// why do we need this check?
|
|
235
|
-
// hostname n/a for file protocol (example, when using electron, ionic)
|
|
236
|
-
// see: https://github.com/webpack/webpack-dev-server/pull/384
|
|
237
|
-
// eslint-disable-next-line no-bitwise
|
|
238
|
-
if (self.location.hostname && !!~self.location.protocol.indexOf('http')) {
|
|
239
|
-
hostname = self.location.hostname;
|
|
240
|
-
}
|
|
241
|
-
} // `hostname` can be empty when the script path is relative. In that case, specifying
|
|
242
|
-
// a protocol would result in an invalid URL.
|
|
243
|
-
// When https is used in the app, secure websockets are always necessary
|
|
244
|
-
// because the browser doesn't accept non-secure websockets.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (hostname && (self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')) {
|
|
248
|
-
protocol = self.location.protocol;
|
|
249
|
-
} // default values of the sock url if they are not provided
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
var sockHost = hostname;
|
|
253
|
-
var sockPath = '/sockjs-node';
|
|
254
|
-
var sockPort = urlParts.port;
|
|
255
|
-
|
|
256
|
-
if (urlParts.path !== null && // eslint-disable-next-line no-undefined
|
|
257
|
-
urlParts.path !== undefined && urlParts.path !== '/') {
|
|
258
|
-
var parsedQuery = querystring.parse(urlParts.path); // all of these sock url params are optionally passed in through
|
|
259
|
-
// __resourceQuery, so we need to fall back to the default if
|
|
260
|
-
// they are not provided
|
|
261
|
-
|
|
262
|
-
sockHost = parsedQuery.sockHost || sockHost;
|
|
263
|
-
sockPath = parsedQuery.sockPath || sockPath;
|
|
264
|
-
sockPort = parsedQuery.sockPort || sockPort;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
var socketUrl = url.format({
|
|
268
|
-
protocol: protocol,
|
|
269
|
-
auth: urlParts.auth,
|
|
270
|
-
hostname: sockHost,
|
|
271
|
-
port: sockPort,
|
|
272
|
-
// If sockPath is provided it'll be passed in via the __resourceQuery as a
|
|
273
|
-
// query param so it has to be parsed out of the querystring in order for the
|
|
274
|
-
// client to open the socket to the correct location.
|
|
275
|
-
pathname: sockPath
|
|
276
|
-
});
|
|
277
|
-
socket(socketUrl, onSocketMsg);
|
|
176
|
+
socket(socketUrl, onSocketMessage);
|