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/overlay.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
var ansiHTML = require('ansi-html');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _require = require('html-entities'),
|
|
7
|
+
AllHtmlEntities = _require.AllHtmlEntities;
|
|
7
8
|
|
|
8
|
-
var entities = new
|
|
9
|
+
var entities = new AllHtmlEntities();
|
|
9
10
|
var colors = {
|
|
10
11
|
reset: ['transparent', 'transparent'],
|
|
11
12
|
black: '181818',
|
|
@@ -18,6 +19,9 @@ var colors = {
|
|
|
18
19
|
lightgrey: 'EBE7E3',
|
|
19
20
|
darkgrey: '6D7891'
|
|
20
21
|
};
|
|
22
|
+
var overlayIframe = null;
|
|
23
|
+
var overlayDiv = null;
|
|
24
|
+
var lastOnOverlayDivReady = null;
|
|
21
25
|
ansiHTML.setColors(colors);
|
|
22
26
|
|
|
23
27
|
function createOverlayIframe(onIframeLoad) {
|
|
@@ -60,10 +64,6 @@ function addOverlayDivTo(iframe) {
|
|
|
60
64
|
return div;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
var overlayIframe = null;
|
|
64
|
-
var overlayDiv = null;
|
|
65
|
-
var lastOnOverlayDivReady = null;
|
|
66
|
-
|
|
67
67
|
function ensureOverlayDivExists(onOverlayDivReady) {
|
|
68
68
|
if (overlayDiv) {
|
|
69
69
|
// Everything is ready, call the callback right away.
|
|
@@ -76,7 +76,7 @@ function ensureOverlayDivExists(onOverlayDivReady) {
|
|
|
76
76
|
lastOnOverlayDivReady = onOverlayDivReady;
|
|
77
77
|
|
|
78
78
|
if (overlayIframe) {
|
|
79
|
-
// We'
|
|
79
|
+
// We've already created it.
|
|
80
80
|
return;
|
|
81
81
|
} // Create iframe and, when it is ready, a div inside it.
|
|
82
82
|
|
|
@@ -90,16 +90,10 @@ function ensureOverlayDivExists(onOverlayDivReady) {
|
|
|
90
90
|
// We delay adding it so `overlayIframe` is set when `onIframeLoad` fires.
|
|
91
91
|
|
|
92
92
|
document.body.appendChild(overlayIframe);
|
|
93
|
-
}
|
|
93
|
+
} // Successful compilation.
|
|
94
94
|
|
|
95
|
-
function showMessageOverlay(message) {
|
|
96
|
-
ensureOverlayDivExists(function (div) {
|
|
97
|
-
// Make it look similar to our terminal.
|
|
98
|
-
div.innerHTML = "<span style=\"color: #".concat(colors.red, "\">Failed to compile.</span><br><br>").concat(ansiHTML(entities.encode(message)));
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
95
|
|
|
102
|
-
function
|
|
96
|
+
function clear() {
|
|
103
97
|
if (!overlayDiv) {
|
|
104
98
|
// It is not there in the first place.
|
|
105
99
|
return;
|
|
@@ -110,14 +104,17 @@ function destroyErrorOverlay() {
|
|
|
110
104
|
overlayDiv = null;
|
|
111
105
|
overlayIframe = null;
|
|
112
106
|
lastOnOverlayDivReady = null;
|
|
113
|
-
} //
|
|
114
|
-
|
|
107
|
+
} // Compilation with errors (e.g. syntax error or missing modules).
|
|
115
108
|
|
|
116
|
-
exports.clear = function handleSuccess() {
|
|
117
|
-
destroyErrorOverlay();
|
|
118
|
-
}; // Compilation with errors (e.g. syntax error or missing modules).
|
|
119
109
|
|
|
110
|
+
function showMessage(messages) {
|
|
111
|
+
ensureOverlayDivExists(function (div) {
|
|
112
|
+
// Make it look similar to our terminal.
|
|
113
|
+
div.innerHTML = "<span style=\"color: #".concat(colors.red, "\">Failed to compile.</span><br><br>").concat(ansiHTML(entities.encode(messages[0])));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
120
116
|
|
|
121
|
-
exports
|
|
122
|
-
|
|
117
|
+
module.exports = {
|
|
118
|
+
clear: clear,
|
|
119
|
+
showMessage: showMessage
|
|
123
120
|
};
|
package/client/socket.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/* global __webpack_dev_server_client__ */
|
|
3
|
+
|
|
4
|
+
/* eslint-disable
|
|
5
|
+
camelcase
|
|
6
|
+
*/
|
|
7
|
+
// this SockJSClient is here as a default fallback, in case inline mode
|
|
8
|
+
// is off or the client is not injected. This will be switched to
|
|
9
|
+
// WebsocketClient when it becomes the default
|
|
10
|
+
// important: the path to SockJSClient here is made to work in the 'client'
|
|
11
|
+
// directory, but is updated via the webpack compilation when compiled from
|
|
12
|
+
// the 'client-src' directory
|
|
13
|
+
|
|
14
|
+
var Client = typeof __webpack_dev_server_client__ !== 'undefined' ? __webpack_dev_server_client__ : // eslint-disable-next-line import/no-unresolved
|
|
15
|
+
require('./clients/SockJSClient');
|
|
5
16
|
var retries = 0;
|
|
6
|
-
var
|
|
17
|
+
var client = null;
|
|
7
18
|
|
|
8
19
|
var socket = function initSocket(url, handlers) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
sock.onopen = function onopen() {
|
|
20
|
+
client = new Client(url);
|
|
21
|
+
client.onOpen(function () {
|
|
12
22
|
retries = 0;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
sock.onclose = function onclose() {
|
|
23
|
+
});
|
|
24
|
+
client.onClose(function () {
|
|
16
25
|
if (retries === 0) {
|
|
17
26
|
handlers.close();
|
|
18
27
|
} // Try to reconnect.
|
|
19
28
|
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
client = null; // After 10 retries stop trying, to prevent logspam.
|
|
22
31
|
|
|
23
32
|
if (retries <= 10) {
|
|
24
33
|
// Exponentially increase timeout to reconnect.
|
|
@@ -30,16 +39,14 @@ var socket = function initSocket(url, handlers) {
|
|
|
30
39
|
socket(url, handlers);
|
|
31
40
|
}, retryInMs);
|
|
32
41
|
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// This assumes that all data sent via the websocket is JSON.
|
|
37
|
-
var msg = JSON.parse(e.data);
|
|
42
|
+
});
|
|
43
|
+
client.onMessage(function (data) {
|
|
44
|
+
var msg = JSON.parse(data);
|
|
38
45
|
|
|
39
46
|
if (handlers[msg.type]) {
|
|
40
47
|
handlers[msg.type](msg.data);
|
|
41
48
|
}
|
|
42
|
-
};
|
|
49
|
+
});
|
|
43
50
|
};
|
|
44
51
|
|
|
45
52
|
module.exports = socket;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* global self */
|
|
3
|
+
|
|
4
|
+
var url = require('url');
|
|
5
|
+
|
|
6
|
+
var querystring = require('querystring');
|
|
7
|
+
|
|
8
|
+
var getCurrentScriptSource = require('./getCurrentScriptSource');
|
|
9
|
+
|
|
10
|
+
function createSocketUrl(resourceQuery) {
|
|
11
|
+
var urlParts;
|
|
12
|
+
|
|
13
|
+
if (typeof resourceQuery === 'string' && resourceQuery !== '') {
|
|
14
|
+
// If this bundle is inlined, use the resource query to get the correct url.
|
|
15
|
+
urlParts = url.parse(resourceQuery.substr(1));
|
|
16
|
+
} else {
|
|
17
|
+
// Else, get the url from the <script> this file was called with.
|
|
18
|
+
var scriptHost = getCurrentScriptSource(); // eslint-disable-next-line no-useless-escape
|
|
19
|
+
|
|
20
|
+
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
|
|
21
|
+
urlParts = url.parse(scriptHost || '/', false, true);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!urlParts.port || urlParts.port === '0') {
|
|
25
|
+
urlParts.port = self.location.port;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _urlParts = urlParts,
|
|
29
|
+
auth = _urlParts.auth,
|
|
30
|
+
path = _urlParts.path;
|
|
31
|
+
var _urlParts2 = urlParts,
|
|
32
|
+
hostname = _urlParts2.hostname,
|
|
33
|
+
protocol = _urlParts2.protocol; // check ipv4 and ipv6 `all hostname`
|
|
34
|
+
// why do we need this check?
|
|
35
|
+
// hostname n/a for file protocol (example, when using electron, ionic)
|
|
36
|
+
// see: https://github.com/webpack/webpack-dev-server/pull/384
|
|
37
|
+
|
|
38
|
+
if ((hostname === '0.0.0.0' || hostname === '::') && self.location.hostname && // eslint-disable-next-line no-bitwise
|
|
39
|
+
!!~self.location.protocol.indexOf('http')) {
|
|
40
|
+
hostname = self.location.hostname;
|
|
41
|
+
} // `hostname` can be empty when the script path is relative. In that case, specifying
|
|
42
|
+
// a protocol would result in an invalid URL.
|
|
43
|
+
// When https is used in the app, secure websockets are always necessary
|
|
44
|
+
// because the browser doesn't accept non-secure websockets.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if (hostname && (self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')) {
|
|
48
|
+
protocol = self.location.protocol;
|
|
49
|
+
} // default values of the sock url if they are not provided
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
var sockHost = hostname;
|
|
53
|
+
var sockPath = '/sockjs-node';
|
|
54
|
+
var sockPort = urlParts.port; // eslint-disable-next-line no-undefined
|
|
55
|
+
|
|
56
|
+
if (path !== null && path !== undefined && path !== '/') {
|
|
57
|
+
var parsedQuery = querystring.parse(path); // all of these sock url params are optionally passed in through
|
|
58
|
+
// resourceQuery, so we need to fall back to the default if
|
|
59
|
+
// they are not provided
|
|
60
|
+
|
|
61
|
+
sockHost = parsedQuery.sockHost || sockHost;
|
|
62
|
+
sockPath = parsedQuery.sockPath || sockPath;
|
|
63
|
+
sockPort = parsedQuery.sockPort || sockPort;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return url.format({
|
|
67
|
+
protocol: protocol,
|
|
68
|
+
auth: auth,
|
|
69
|
+
hostname: sockHost,
|
|
70
|
+
port: sockPort,
|
|
71
|
+
// If sockPath is provided it'll be passed in via the resourceQuery as a
|
|
72
|
+
// query param so it has to be parsed out of the querystring in order for the
|
|
73
|
+
// client to open the socket to the correct location.
|
|
74
|
+
pathname: sockPath
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = createSocketUrl;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var log = require('loglevel').getLogger('webpack-dev-server');
|
|
4
|
+
|
|
5
|
+
var INFO = 'info';
|
|
6
|
+
var WARN = 'warn';
|
|
7
|
+
var ERROR = 'error';
|
|
8
|
+
var DEBUG = 'debug';
|
|
9
|
+
var TRACE = 'trace';
|
|
10
|
+
var SILENT = 'silent'; // deprecated
|
|
11
|
+
// TODO: remove these at major released
|
|
12
|
+
// https://github.com/webpack/webpack-dev-server/pull/1825
|
|
13
|
+
|
|
14
|
+
var WARNING = 'warning';
|
|
15
|
+
var NONE = 'none'; // Set the default log level
|
|
16
|
+
|
|
17
|
+
log.setDefaultLevel(INFO);
|
|
18
|
+
|
|
19
|
+
function setLogLevel(level) {
|
|
20
|
+
switch (level) {
|
|
21
|
+
case INFO:
|
|
22
|
+
case WARN:
|
|
23
|
+
case ERROR:
|
|
24
|
+
case DEBUG:
|
|
25
|
+
case TRACE:
|
|
26
|
+
log.setLevel(level);
|
|
27
|
+
break;
|
|
28
|
+
// deprecated
|
|
29
|
+
|
|
30
|
+
case WARNING:
|
|
31
|
+
// loglevel's warning name is different from webpack's
|
|
32
|
+
log.setLevel('warn');
|
|
33
|
+
break;
|
|
34
|
+
// deprecated
|
|
35
|
+
|
|
36
|
+
case NONE:
|
|
37
|
+
case SILENT:
|
|
38
|
+
log.disableAll();
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
log.error("[WDS] Unknown clientLogLevel '".concat(level, "'"));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
log: log,
|
|
48
|
+
setLogLevel: setLogLevel
|
|
49
|
+
};
|
package/lib/Server.js
CHANGED
|
@@ -30,8 +30,8 @@ const status = require('./utils/status');
|
|
|
30
30
|
const createDomain = require('./utils/createDomain');
|
|
31
31
|
const runBonjour = require('./utils/runBonjour');
|
|
32
32
|
const routes = require('./utils/routes');
|
|
33
|
+
const getSocketServerImplementation = require('./utils/getSocketServerImplementation');
|
|
33
34
|
const schema = require('./options.json');
|
|
34
|
-
const SockJSServer = require('./servers/SockJSServer');
|
|
35
35
|
|
|
36
36
|
// Workaround for node ^8.6.0, ^9.0.0
|
|
37
37
|
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
|
|
@@ -67,6 +67,19 @@ class Server {
|
|
|
67
67
|
|
|
68
68
|
this.log = _log || createLogger(options);
|
|
69
69
|
|
|
70
|
+
if (this.options.serverMode === undefined) {
|
|
71
|
+
this.options.serverMode = 'sockjs';
|
|
72
|
+
} else {
|
|
73
|
+
this.log.warn(
|
|
74
|
+
'serverMode is an experimental option, meaning its usage could potentially change without warning'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// this.SocketServerImplementation is a class, so it must be instantiated before use
|
|
79
|
+
this.socketServerImplementation = getSocketServerImplementation(
|
|
80
|
+
this.options
|
|
81
|
+
);
|
|
82
|
+
|
|
70
83
|
this.originalStats =
|
|
71
84
|
this.options.stats && Object.keys(this.options.stats).length
|
|
72
85
|
? this.options.stats
|
|
@@ -92,11 +105,8 @@ class Server {
|
|
|
92
105
|
if (!this.options.watchOptions) {
|
|
93
106
|
this.options.watchOptions = {};
|
|
94
107
|
}
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
/node_modules/,
|
|
98
|
-
];
|
|
99
|
-
this.watchOptions = this.options.watchOptions;
|
|
108
|
+
|
|
109
|
+
this.watchOptions = options.watchOptions || {};
|
|
100
110
|
|
|
101
111
|
// Replace leading and trailing slashes to normalize path
|
|
102
112
|
this.sockPath = `/${
|
|
@@ -655,7 +665,8 @@ class Server {
|
|
|
655
665
|
}
|
|
656
666
|
|
|
657
667
|
createSocketServer() {
|
|
658
|
-
|
|
668
|
+
const SocketServerImplementation = this.socketServerImplementation;
|
|
669
|
+
this.socketServer = new SocketServerImplementation(this);
|
|
659
670
|
|
|
660
671
|
this.socketServer.onConnection((connection) => {
|
|
661
672
|
if (!connection) {
|
|
@@ -683,10 +694,15 @@ class Server {
|
|
|
683
694
|
}
|
|
684
695
|
});
|
|
685
696
|
|
|
697
|
+
if (this.clientLogLevel) {
|
|
698
|
+
this.sockWrite([connection], 'log-level', this.clientLogLevel);
|
|
699
|
+
}
|
|
700
|
+
|
|
686
701
|
if (this.hot) {
|
|
687
702
|
this.sockWrite([connection], 'hot');
|
|
688
703
|
}
|
|
689
704
|
|
|
705
|
+
// TODO: change condition at major version
|
|
690
706
|
if (this.options.liveReload !== false) {
|
|
691
707
|
this.sockWrite([connection], 'liveReload', this.options.liveReload);
|
|
692
708
|
}
|
|
@@ -699,10 +715,6 @@ class Server {
|
|
|
699
715
|
this.sockWrite([connection], 'overlay', this.clientOverlay);
|
|
700
716
|
}
|
|
701
717
|
|
|
702
|
-
if (this.clientLogLevel) {
|
|
703
|
-
this.sockWrite([connection], 'log-level', this.clientLogLevel);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
718
|
if (!this._stats) {
|
|
707
719
|
return;
|
|
708
720
|
}
|
package/lib/options.json
CHANGED
|
@@ -297,6 +297,16 @@
|
|
|
297
297
|
"serveIndex": {
|
|
298
298
|
"type": "boolean"
|
|
299
299
|
},
|
|
300
|
+
"serverMode": {
|
|
301
|
+
"anyOf": [
|
|
302
|
+
{
|
|
303
|
+
"type": "string"
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"instanceof": "Function"
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
},
|
|
300
310
|
"serverSideRender": {
|
|
301
311
|
"type": "boolean"
|
|
302
312
|
},
|
|
@@ -379,7 +389,7 @@
|
|
|
379
389
|
"bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)",
|
|
380
390
|
"ca": "should be {String|Buffer}",
|
|
381
391
|
"cert": "should be {String|Buffer}",
|
|
382
|
-
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ '
|
|
392
|
+
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'none', 'silent', 'info', 'debug', 'trace', 'error', 'warning', 'warn' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
|
|
383
393
|
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
|
|
384
394
|
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
|
|
385
395
|
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
|
|
@@ -394,8 +404,8 @@
|
|
|
394
404
|
"http2": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttp2)",
|
|
395
405
|
"https": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverhttps)",
|
|
396
406
|
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",
|
|
397
|
-
"injectClient": "should be {Boolean|Function}",
|
|
398
|
-
"injectHot": "should be {Boolean|Function}",
|
|
407
|
+
"injectClient": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverinjectclient)",
|
|
408
|
+
"injectHot": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverinjecthot)",
|
|
399
409
|
"inline": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverinline)",
|
|
400
410
|
"key": "should be {String|Buffer}",
|
|
401
411
|
"lazy": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlazy-)",
|
|
@@ -420,6 +430,7 @@
|
|
|
420
430
|
"reporter": "should be {Function} (https://github.com/webpack/webpack-dev-middleware#reporter)",
|
|
421
431
|
"requestCert": "should be {Boolean}",
|
|
422
432
|
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
|
|
433
|
+
"serverMode": "should be {String|Function} (https://webpack.js.org/configuration/dev-server/#devserverservermode-)",
|
|
423
434
|
"serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
|
|
424
435
|
"setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserversetup)",
|
|
425
436
|
"sockHost": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockhost)",
|
package/lib/utils/findPort.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const pRetry = require('p-retry');
|
|
4
|
+
const portfinder = require('portfinder');
|
|
4
5
|
const defaultPort = require('./defaultPort');
|
|
5
6
|
const defaultTo = require('./defaultTo');
|
|
6
7
|
const tryParseInt = require('./tryParseInt');
|
|
7
8
|
|
|
9
|
+
function runPortFinder() {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
portfinder.basePort = defaultPort;
|
|
12
|
+
portfinder.getPort((error, port) => {
|
|
13
|
+
if (error) {
|
|
14
|
+
return reject(error);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return resolve(port);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
function findPort(port) {
|
|
9
|
-
if (
|
|
23
|
+
if (port) {
|
|
10
24
|
return Promise.resolve(port);
|
|
11
25
|
}
|
|
12
26
|
|
|
@@ -19,10 +33,7 @@ function findPort(port) {
|
|
|
19
33
|
3
|
|
20
34
|
);
|
|
21
35
|
|
|
22
|
-
return
|
|
23
|
-
port: defaultPort,
|
|
24
|
-
stopPort: defaultPort + defaultPortRetry,
|
|
25
|
-
});
|
|
36
|
+
return pRetry(runPortFinder, { retries: defaultPortRetry });
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
module.exports = findPort;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getSocketServerImplementation(options) {
|
|
4
|
+
let ServerImplementation;
|
|
5
|
+
let serverImplFound = true;
|
|
6
|
+
switch (typeof options.serverMode) {
|
|
7
|
+
case 'string':
|
|
8
|
+
// could be 'sockjs', in the future 'ws', or a path that should be required
|
|
9
|
+
if (options.serverMode === 'sockjs') {
|
|
10
|
+
// eslint-disable-next-line global-require
|
|
11
|
+
ServerImplementation = require('../servers/SockJSServer');
|
|
12
|
+
} else {
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
15
|
+
ServerImplementation = require(options.serverMode);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
serverImplFound = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
case 'function':
|
|
22
|
+
// potentially do more checks here to confirm that the user implemented this properlly
|
|
23
|
+
// since errors could be difficult to understand
|
|
24
|
+
ServerImplementation = options.serverMode;
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
serverImplFound = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!serverImplFound) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
|
|
33
|
+
'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
|
|
34
|
+
'via require.resolve(...), or the class itself which extends BaseServer'
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return ServerImplementation;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = getSocketServerImplementation;
|
package/lib/utils/runOpen.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
const open = require('opn');
|
|
4
4
|
|
|
5
5
|
function runOpen(uri, options, log) {
|
|
6
|
-
|
|
6
|
+
// https://github.com/webpack/webpack-dev-server/issues/1990
|
|
7
|
+
let openOptions = { wait: false };
|
|
7
8
|
let openMessage = 'Unable to open browser';
|
|
8
9
|
|
|
9
10
|
if (typeof options.open === 'string') {
|
|
10
|
-
openOptions = { app: options.open };
|
|
11
|
+
openOptions = Object.assign({}, openOptions, { app: options.open });
|
|
11
12
|
openMessage += `: ${options.open}`;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
|
|
15
|
+
return open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
|
|
15
16
|
log.warn(
|
|
16
17
|
`${openMessage}. If you are running in a headless environment, please do not use the --open flag`
|
|
17
18
|
);
|
package/lib/utils/tryParseInt.js
CHANGED
|
@@ -48,6 +48,14 @@ function updateCompiler(compiler, options) {
|
|
|
48
48
|
compilers.forEach((compiler) => {
|
|
49
49
|
const config = compiler.options;
|
|
50
50
|
compiler.hooks.entryOption.call(config.context, config.entry);
|
|
51
|
+
|
|
52
|
+
const providePlugin = new webpack.ProvidePlugin({
|
|
53
|
+
// SockJSClient.getClientPath(options)
|
|
54
|
+
__webpack_dev_server_client__: require.resolve(
|
|
55
|
+
'../../client/clients/SockJSClient.js'
|
|
56
|
+
),
|
|
57
|
+
});
|
|
58
|
+
providePlugin.apply(compiler);
|
|
51
59
|
});
|
|
52
60
|
|
|
53
61
|
// do not apply the plugin unless it didn't exist before.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-dev-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.2",
|
|
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",
|
|
@@ -19,16 +19,18 @@
|
|
|
19
19
|
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
20
20
|
"commitlint": "commitlint --from=master",
|
|
21
21
|
"security": "npm audit",
|
|
22
|
-
"test:only": "jest
|
|
22
|
+
"test:only": "jest",
|
|
23
23
|
"test:coverage": "npm run test:only -- --coverage",
|
|
24
24
|
"test:watch": "npm run test:coverage --watch",
|
|
25
25
|
"test": "npm run test:coverage",
|
|
26
26
|
"pretest": "npm run lint",
|
|
27
|
-
"prepare": "rimraf ./ssl/*.pem && npm run
|
|
28
|
-
"
|
|
29
|
-
"build:
|
|
30
|
-
"build:
|
|
31
|
-
"build:
|
|
27
|
+
"prepare": "rimraf ./ssl/*.pem && npm run build:client",
|
|
28
|
+
"build:client:default": "babel client-src/default --out-dir client --ignore \"./client-src/default/*.config.js\"",
|
|
29
|
+
"build:client:clients": "babel client-src/clients --out-dir client/clients",
|
|
30
|
+
"build:client:index": "webpack ./client-src/default/index.js -o client/index.bundle.js --color --config client-src/default/webpack.config.js",
|
|
31
|
+
"build:client:live": "webpack ./client-src/live/index.js -o client/live.bundle.js --color --config client-src/live/webpack.config.js",
|
|
32
|
+
"build:client:sockjs": "webpack ./client-src/sockjs/index.js -o client/sockjs.bundle.js --color --config client-src/sockjs/webpack.config.js",
|
|
33
|
+
"build:client": "rimraf ./client/* && npm-run-all -s -l -p \"build:client:**\"",
|
|
32
34
|
"webpack-dev-server": "cd $INIT_CWD && node ../../../bin/webpack-dev-server.js",
|
|
33
35
|
"release": "standard-version"
|
|
34
36
|
},
|
|
@@ -47,8 +49,9 @@
|
|
|
47
49
|
"internal-ip": "^4.3.0",
|
|
48
50
|
"ip": "^1.1.5",
|
|
49
51
|
"killable": "^1.0.1",
|
|
50
|
-
"loglevel": "^1.6.
|
|
52
|
+
"loglevel": "^1.6.3",
|
|
51
53
|
"opn": "^5.5.0",
|
|
54
|
+
"p-retry": "^3.0.1",
|
|
52
55
|
"portfinder": "^1.0.20",
|
|
53
56
|
"schema-utils": "^1.0.0",
|
|
54
57
|
"selfsigned": "^1.10.4",
|
|
@@ -67,42 +70,43 @@
|
|
|
67
70
|
"devDependencies": {
|
|
68
71
|
"@babel/cli": "^7.4.4",
|
|
69
72
|
"@babel/core": "^7.4.5",
|
|
73
|
+
"@babel/plugin-transform-runtime": "^7.4.4",
|
|
70
74
|
"@babel/preset-env": "^7.4.5",
|
|
71
|
-
"@commitlint/cli": "^
|
|
72
|
-
"@commitlint/config-conventional": "^
|
|
75
|
+
"@commitlint/cli": "^8.0.0",
|
|
76
|
+
"@commitlint/config-conventional": "^8.0.0",
|
|
73
77
|
"babel-loader": "^8.0.6",
|
|
74
78
|
"body-parser": "^1.19.0",
|
|
75
|
-
"commitlint-azure-pipelines-cli": "^1.0.
|
|
79
|
+
"commitlint-azure-pipelines-cli": "^1.0.2",
|
|
76
80
|
"copy-webpack-plugin": "^5.0.3",
|
|
77
81
|
"css-loader": "^2.1.1",
|
|
78
82
|
"eslint": "^5.16.0",
|
|
79
|
-
"eslint-config-prettier": "^
|
|
83
|
+
"eslint-config-prettier": "^5.0.0",
|
|
80
84
|
"eslint-config-webpack": "^1.2.5",
|
|
81
85
|
"eslint-plugin-import": "^2.17.3",
|
|
82
86
|
"execa": "^1.0.0",
|
|
83
87
|
"file-loader": "^3.0.1",
|
|
84
88
|
"html-loader": "^0.5.5",
|
|
85
89
|
"html-webpack-plugin": "^3.2.0",
|
|
86
|
-
"husky": "^2.
|
|
90
|
+
"husky": "^2.4.1",
|
|
87
91
|
"jest": "^24.8.0",
|
|
88
92
|
"jest-junit": "^6.4.0",
|
|
89
93
|
"jquery": "^3.4.1",
|
|
90
94
|
"less": "^3.9.0",
|
|
91
95
|
"less-loader": "^5.0.0",
|
|
92
|
-
"lint-staged": "^8.1
|
|
96
|
+
"lint-staged": "^8.2.1",
|
|
93
97
|
"marked": "^0.6.2",
|
|
94
98
|
"memfs": "^2.15.4",
|
|
95
99
|
"npm-run-all": "^4.1.5",
|
|
96
|
-
"
|
|
97
|
-
"prettier": "^1.17.1",
|
|
100
|
+
"prettier": "^1.18.2",
|
|
98
101
|
"puppeteer": "^1.17.0",
|
|
99
102
|
"rimraf": "^2.6.3",
|
|
100
103
|
"standard-version": "^6.0.1",
|
|
101
104
|
"style-loader": "^0.23.1",
|
|
102
105
|
"supertest": "^4.0.2",
|
|
106
|
+
"tcp-port-used": "^1.0.1",
|
|
103
107
|
"url-loader": "^1.1.2",
|
|
104
|
-
"webpack": "^4.
|
|
105
|
-
"webpack-cli": "^3.3.
|
|
108
|
+
"webpack": "^4.34.0",
|
|
109
|
+
"webpack-cli": "^3.3.4",
|
|
106
110
|
"ws": "^6.2.1"
|
|
107
111
|
},
|
|
108
112
|
"peerDependencies": {
|