webpack-dev-server 4.0.0-rc.0 → 4.1.1

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/overlay.js CHANGED
@@ -1,22 +1,18 @@
1
- 'use strict'; // The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
1
+ // The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
2
2
  // They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).
3
-
4
- var ansiHTML = require('ansi-html');
5
-
6
- var _require = require('html-entities'),
7
- encode = _require.encode;
8
-
3
+ import ansiHTML from "ansi-html-community";
4
+ import { encode } from "html-entities";
9
5
  var colors = {
10
- reset: ['transparent', 'transparent'],
11
- black: '181818',
12
- red: 'E36049',
13
- green: 'B3CB74',
14
- yellow: 'FFD080',
15
- blue: '7CAFC2',
16
- magenta: '7FACCA',
17
- cyan: 'C3C2EF',
18
- lightgrey: 'EBE7E3',
19
- darkgrey: '6D7891'
6
+ reset: ["transparent", "transparent"],
7
+ black: "181818",
8
+ red: "E36049",
9
+ green: "B3CB74",
10
+ yellow: "FFD080",
11
+ blue: "7CAFC2",
12
+ magenta: "7FACCA",
13
+ cyan: "C3C2EF",
14
+ lightgrey: "EBE7E3",
15
+ darkgrey: "6D7891"
20
16
  };
21
17
  var iframeContainerElement;
22
18
  var containerElement;
@@ -24,57 +20,57 @@ var onLoadQueue = [];
24
20
  ansiHTML.setColors(colors);
25
21
 
26
22
  function createContainer() {
27
- iframeContainerElement = document.createElement('iframe');
28
- iframeContainerElement.id = 'webpack-dev-server-client-overlay';
29
- iframeContainerElement.src = 'about:blank';
30
- iframeContainerElement.style.position = 'fixed';
23
+ iframeContainerElement = document.createElement("iframe");
24
+ iframeContainerElement.id = "webpack-dev-server-client-overlay";
25
+ iframeContainerElement.src = "about:blank";
26
+ iframeContainerElement.style.position = "fixed";
31
27
  iframeContainerElement.style.left = 0;
32
28
  iframeContainerElement.style.top = 0;
33
29
  iframeContainerElement.style.right = 0;
34
30
  iframeContainerElement.style.bottom = 0;
35
- iframeContainerElement.style.width = '100vw';
36
- iframeContainerElement.style.height = '100vh';
37
- iframeContainerElement.style.border = 'none';
31
+ iframeContainerElement.style.width = "100vw";
32
+ iframeContainerElement.style.height = "100vh";
33
+ iframeContainerElement.style.border = "none";
38
34
  iframeContainerElement.style.zIndex = 9999999999;
39
35
 
40
36
  iframeContainerElement.onload = function () {
41
- containerElement = iframeContainerElement.contentDocument.createElement('div');
42
- containerElement.id = 'webpack-dev-server-client-overlay-div';
43
- containerElement.style.position = 'fixed';
44
- containerElement.style.boxSizing = 'border-box';
37
+ containerElement = iframeContainerElement.contentDocument.createElement("div");
38
+ containerElement.id = "webpack-dev-server-client-overlay-div";
39
+ containerElement.style.position = "fixed";
40
+ containerElement.style.boxSizing = "border-box";
45
41
  containerElement.style.left = 0;
46
42
  containerElement.style.top = 0;
47
43
  containerElement.style.right = 0;
48
44
  containerElement.style.bottom = 0;
49
- containerElement.style.width = '100vw';
50
- containerElement.style.height = '100vh';
51
- containerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.85)';
52
- containerElement.style.color = '#E8E8E8';
53
- containerElement.style.fontFamily = 'Menlo, Consolas, monospace';
54
- containerElement.style.fontSize = 'large';
55
- containerElement.style.padding = '2rem';
56
- containerElement.style.lineHeight = '1.2';
57
- containerElement.style.whiteSpace = 'pre-wrap';
58
- containerElement.style.overflow = 'auto';
59
- var headerElement = document.createElement('span');
60
- headerElement.innerText = 'Compiled with problems:';
61
- var closeButtonElement = document.createElement('button');
62
- closeButtonElement.innerText = 'X';
63
- closeButtonElement.style.background = 'transparent';
64
- closeButtonElement.style.border = 'none';
65
- closeButtonElement.style.fontSize = '20px';
66
- closeButtonElement.style.fontWeight = 'bold';
67
- closeButtonElement.style.color = 'white';
68
- closeButtonElement.style.cursor = 'pointer';
69
- closeButtonElement.style.cssFloat = 'right';
70
- closeButtonElement.style.styleFloat = 'right';
71
- closeButtonElement.addEventListener('click', function () {
45
+ containerElement.style.width = "100vw";
46
+ containerElement.style.height = "100vh";
47
+ containerElement.style.backgroundColor = "rgba(0, 0, 0, 0.85)";
48
+ containerElement.style.color = "#E8E8E8";
49
+ containerElement.style.fontFamily = "Menlo, Consolas, monospace";
50
+ containerElement.style.fontSize = "large";
51
+ containerElement.style.padding = "2rem";
52
+ containerElement.style.lineHeight = "1.2";
53
+ containerElement.style.whiteSpace = "pre-wrap";
54
+ containerElement.style.overflow = "auto";
55
+ var headerElement = document.createElement("span");
56
+ headerElement.innerText = "Compiled with problems:";
57
+ var closeButtonElement = document.createElement("button");
58
+ closeButtonElement.innerText = "X";
59
+ closeButtonElement.style.background = "transparent";
60
+ closeButtonElement.style.border = "none";
61
+ closeButtonElement.style.fontSize = "20px";
62
+ closeButtonElement.style.fontWeight = "bold";
63
+ closeButtonElement.style.color = "white";
64
+ closeButtonElement.style.cursor = "pointer";
65
+ closeButtonElement.style.cssFloat = "right";
66
+ closeButtonElement.style.styleFloat = "right";
67
+ closeButtonElement.addEventListener("click", function () {
72
68
  hide();
73
69
  });
74
70
  containerElement.appendChild(headerElement);
75
71
  containerElement.appendChild(closeButtonElement);
76
- containerElement.appendChild(document.createElement('br'));
77
- containerElement.appendChild(document.createElement('br'));
72
+ containerElement.appendChild(document.createElement("br"));
73
+ containerElement.appendChild(document.createElement("br"));
78
74
  iframeContainerElement.contentDocument.body.appendChild(containerElement);
79
75
  onLoadQueue.forEach(function (onLoad) {
80
76
  onLoad(containerElement);
@@ -118,27 +114,24 @@ function hide() {
118
114
  function show(messages, type) {
119
115
  ensureOverlayExists(function () {
120
116
  messages.forEach(function (message) {
121
- var entryElement = document.createElement('div');
122
- var typeElement = document.createElement('span');
123
- typeElement.innerText = type === 'warnings' ? 'Warning:' : 'Error:';
117
+ var entryElement = document.createElement("div");
118
+ var typeElement = document.createElement("span");
119
+ typeElement.innerText = type === "warnings" ? "Warning:" : "Error:";
124
120
  typeElement.style.color = "#".concat(colors.red); // Make it look similar to our terminal.
125
121
 
126
122
  var errorMessage = message.message || messages[0];
127
123
  var text = ansiHTML(encode(errorMessage));
128
- var messageTextNode = document.createTextNode(text);
124
+ var messageTextNode = document.createElement("div");
125
+ messageTextNode.innerHTML = text;
129
126
  entryElement.appendChild(typeElement);
130
- entryElement.appendChild(document.createElement('br'));
131
- entryElement.appendChild(document.createElement('br'));
127
+ entryElement.appendChild(document.createElement("br"));
128
+ entryElement.appendChild(document.createElement("br"));
132
129
  entryElement.appendChild(messageTextNode);
133
- entryElement.appendChild(document.createElement('br'));
134
- entryElement.appendChild(document.createElement('br'));
135
- entryElement.appendChild(document.createElement('br'));
130
+ entryElement.appendChild(document.createElement("br"));
131
+ entryElement.appendChild(document.createElement("br"));
136
132
  containerElement.appendChild(entryElement);
137
133
  });
138
134
  });
139
135
  }
140
136
 
141
- module.exports = {
142
- show: show,
143
- hide: hide
144
- };
137
+ export { show, hide };
package/client/socket.js CHANGED
@@ -1,13 +1,13 @@
1
- 'use strict';
2
1
  /* global __webpack_dev_server_client__ */
2
+ import WebSocketClient from "./clients/WebSocketClient.js"; // this WebsocketClient is here as a default fallback, in case the client is not injected
3
3
 
4
- /* eslint-disable
5
- camelcase
6
- */
7
- // this WebsocketClient is here as a default fallback, in case the client is not injected
4
+ /* eslint-disable camelcase */
5
+
6
+ var Client = // eslint-disable-next-line camelcase, no-nested-ternary
7
+ typeof __webpack_dev_server_client__ !== "undefined" ? // eslint-disable-next-line camelcase
8
+ typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;
9
+ /* eslint-enable camelcase */
8
10
 
9
- var Client = typeof __webpack_dev_server_client__ !== 'undefined' ? __webpack_dev_server_client__ : // eslint-disable-next-line import/no-unresolved
10
- require('./clients/WebsocketClient');
11
11
  var retries = 0;
12
12
  var client = null;
13
13
 
@@ -44,4 +44,4 @@ var socket = function initSocket(url, handlers) {
44
44
  });
45
45
  };
46
46
 
47
- module.exports = socket;
47
+ export default socket;
@@ -1,29 +1,26 @@
1
- 'use strict';
2
-
3
- var url = require('url'); // We handle legacy API that is Node.js specific, and a newer API that implements the same WHATWG URL Standard used by web browsers
1
+ import url from "url"; // We handle legacy API that is Node.js specific, and a newer API that implements the same WHATWG URL Standard used by web browsers
4
2
  // Please look at https://nodejs.org/api/url.html#url_url_strings_and_url_objects
5
3
 
6
-
7
4
  function createSocketURL(parsedURL) {
8
5
  var hostname = parsedURL.hostname; // Node.js module parses it as `::`
9
6
  // `new URL(urlString, [baseURLstring])` parses it as '[::]'
10
7
 
11
- var isInAddrAny = hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]'; // why do we need this check?
8
+ var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]"; // why do we need this check?
12
9
  // hostname n/a for file protocol (example, when using electron, ionic)
13
10
  // see: https://github.com/webpack/webpack-dev-server/pull/384
14
11
 
15
- if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf('http') === 0) {
12
+ if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf("http") === 0) {
16
13
  hostname = self.location.hostname;
17
14
  }
18
15
 
19
- var socketURLProtocol = parsedURL.protocol || 'ws:'; // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
16
+ var socketURLProtocol = parsedURL.protocol || self.location.protocol; // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
20
17
 
21
- if (socketURLProtocol === 'auto:' || hostname && isInAddrAny && self.location.protocol === 'https:') {
18
+ if (socketURLProtocol === "auto:" || hostname && isInAddrAny && self.location.protocol === "https:") {
22
19
  socketURLProtocol = self.location.protocol;
23
20
  }
24
21
 
25
- socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
26
- var socketURLAuth = ''; // `new URL(urlString, [baseURLstring])` doesn't have `auth` property
22
+ socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
23
+ var socketURLAuth = ""; // `new URL(urlString, [baseURLstring])` doesn't have `auth` property
27
24
  // Parse authentication credentials in case we need them
28
25
 
29
26
  if (parsedURL.username) {
@@ -32,7 +29,7 @@ function createSocketURL(parsedURL) {
32
29
 
33
30
  if (parsedURL.password) {
34
31
  // Result: <username>:<password>
35
- socketURLAuth = socketURLAuth.concat(':', parsedURL.password);
32
+ socketURLAuth = socketURLAuth.concat(":", parsedURL.password);
36
33
  }
37
34
  } // In case the host is a raw IPv6 address, it can be enclosed in
38
35
  // the brackets as the brackets are needed in the final URL string.
@@ -44,17 +41,17 @@ function createSocketURL(parsedURL) {
44
41
  // so we need to fall back to the default if they are not provided
45
42
 
46
43
 
47
- var socketURLHostname = (hostname || self.location.hostname || 'localhost').replace(/^\[(.*)\]$/, '$1');
44
+ var socketURLHostname = (hostname || self.location.hostname || "localhost").replace(/^\[(.*)\]$/, "$1");
48
45
  var socketURLPort = parsedURL.port;
49
46
 
50
- if (!socketURLPort || socketURLPort === '0') {
47
+ if (!socketURLPort || socketURLPort === "0") {
51
48
  socketURLPort = self.location.port;
52
49
  } // If path is provided it'll be passed in via the resourceQuery as a
53
50
  // query param so it has to be parsed out of the querystring in order for the
54
51
  // client to open the socket to the correct location.
55
52
 
56
53
 
57
- var socketURLPathname = '/ws';
54
+ var socketURLPathname = "/ws";
58
55
 
59
56
  if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
60
57
  socketURLPathname = parsedURL.pathname;
@@ -70,4 +67,4 @@ function createSocketURL(parsedURL) {
70
67
  });
71
68
  }
72
69
 
73
- module.exports = createSocketURL;
70
+ export default createSocketURL;
@@ -1,25 +1,23 @@
1
- 'use strict';
2
-
3
1
  function getCurrentScriptSource() {
4
2
  // `document.currentScript` is the most accurate way to find the current script,
5
3
  // but is not supported in all browsers.
6
4
  if (document.currentScript) {
7
- return document.currentScript.getAttribute('src');
5
+ return document.currentScript.getAttribute("src");
8
6
  } // Fallback to getting all scripts running in the document.
9
7
 
10
8
 
11
9
  var scriptElements = document.scripts || [];
12
10
  var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) {
13
- return element.getAttribute('src');
11
+ return element.getAttribute("src");
14
12
  });
15
13
 
16
14
  if (scriptElementsWithSrc.length > 0) {
17
15
  var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
18
- return currentScript.getAttribute('src');
16
+ return currentScript.getAttribute("src");
19
17
  } // Fail as there was no script to use.
20
18
 
21
19
 
22
- throw new Error('[webpack-dev-server] Failed to get current script source.');
20
+ throw new Error("[webpack-dev-server] Failed to get current script source.");
23
21
  }
24
22
 
25
- module.exports = getCurrentScriptSource;
23
+ export default getCurrentScriptSource;
@@ -1,11 +1,8 @@
1
- 'use strict';
2
-
3
- var logger = require('../modules/logger');
4
-
5
- var name = 'webpack-dev-server'; // default level is set on the client side, so it does not need
1
+ import logger from "../modules/logger/index.js";
2
+ var name = "webpack-dev-server"; // default level is set on the client side, so it does not need
6
3
  // to be set by the CLI or API
7
4
 
8
- var defaultLevel = 'info';
5
+ var defaultLevel = "info";
9
6
 
10
7
  function setLogLevel(level) {
11
8
  logger.configureDefaultLogger({
@@ -14,7 +11,5 @@ function setLogLevel(level) {
14
11
  }
15
12
 
16
13
  setLogLevel(defaultLevel);
17
- module.exports = {
18
- log: logger.getLogger(name),
19
- setLogLevel: setLogLevel
20
- };
14
+ var log = logger.getLogger(name);
15
+ export { log, setLogLevel };
@@ -1,17 +1,14 @@
1
- 'use strict';
2
-
3
- var url = require('url');
4
-
5
- var getCurrentScriptSource = require('./getCurrentScriptSource');
1
+ import url from "url";
2
+ import getCurrentScriptSource from "./getCurrentScriptSource.js";
6
3
 
7
4
  function parseURL(resourceQuery) {
8
5
  var options = {};
9
6
 
10
- if (typeof resourceQuery === 'string' && resourceQuery !== '') {
11
- var searchParams = resourceQuery.substr(1).split('&');
7
+ if (typeof resourceQuery === "string" && resourceQuery !== "") {
8
+ var searchParams = resourceQuery.substr(1).split("&");
12
9
 
13
10
  for (var i = 0; i < searchParams.length; i++) {
14
- var pair = searchParams[i].split('=');
11
+ var pair = searchParams[i].split("=");
15
12
  options[pair[0]] = decodeURIComponent(pair[1]);
16
13
  }
17
14
  } else {
@@ -43,4 +40,4 @@ function parseURL(resourceQuery) {
43
40
  return options;
44
41
  }
45
42
 
46
- module.exports = parseURL;
43
+ export default parseURL;
@@ -1,57 +1,67 @@
1
- 'use strict';
1
+ /* global __webpack_hash__ */
2
+ import hotEmitter from "webpack/hot/emitter.js";
3
+ import { log } from "./log.js";
2
4
 
3
- var _require = require('./log'),
4
- log = _require.log;
5
-
6
- function reloadApp(_ref, _ref2) {
5
+ function reloadApp(_ref, status) {
7
6
  var hot = _ref.hot,
8
7
  liveReload = _ref.liveReload;
9
- var isUnloading = _ref2.isUnloading,
10
- currentHash = _ref2.currentHash;
11
8
 
12
- if (isUnloading) {
9
+ if (status.isUnloading) {
10
+ return;
11
+ } // TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement plugin
12
+
13
+
14
+ var webpackHash = // eslint-disable-next-line camelcase
15
+ typeof __webpack_hash__ !== "undefined" ? // eslint-disable-next-line camelcase
16
+ __webpack_hash__ : status.previousHash || "";
17
+ var isInitial = status.currentHash.indexOf(webpackHash) === 0;
18
+
19
+ if (isInitial) {
20
+ var isLegacyInitial = webpackHash === "" && hot === false && liveReload === true;
21
+
22
+ if (isLegacyInitial) {
23
+ status.previousHash = status.currentHash;
24
+ }
25
+
13
26
  return;
14
27
  }
15
28
 
16
29
  function applyReload(rootWindow, intervalId) {
17
30
  clearInterval(intervalId);
18
- log.info('App updated. Reloading...');
31
+ log.info("App updated. Reloading...");
19
32
  rootWindow.location.reload();
20
33
  }
21
34
 
22
35
  var search = self.location.search.toLowerCase();
23
- var allowToHot = search.indexOf('webpack-dev-server-hot=false') === -1;
24
- var allowToLiveReload = search.indexOf('webpack-dev-server-live-reload=false') === -1;
36
+ var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
37
+ var allowToLiveReload = search.indexOf("webpack-dev-server-live-reload=false") === -1;
25
38
 
26
39
  if (hot && allowToHot) {
27
- log.info('App hot update...');
28
-
29
- var hotEmitter = require('webpack/hot/emitter');
40
+ log.info("App hot update...");
41
+ hotEmitter.emit("webpackHotUpdate", status.currentHash);
30
42
 
31
- hotEmitter.emit('webpackHotUpdate', currentHash);
32
-
33
- if (typeof self !== 'undefined' && self.window) {
43
+ if (typeof self !== "undefined" && self.window) {
34
44
  // broadcast update to window
35
- self.postMessage("webpackHotUpdate".concat(currentHash), '*');
45
+ self.postMessage("webpackHotUpdate".concat(status.currentHash), "*");
36
46
  }
37
47
  } // allow refreshing the page only if liveReload isn't disabled
38
48
  else if (liveReload && allowToLiveReload) {
39
- var rootWindow = self; // use parent window for reload (in case we're in an iframe with no valid src)
49
+ var rootWindow = self; // use parent window for reload (in case we're in an iframe with no valid src)
40
50
 
41
- var intervalId = self.setInterval(function () {
42
- if (rootWindow.location.protocol !== 'about:') {
43
- // reload immediately if protocol is valid
44
- applyReload(rootWindow, intervalId);
45
- } else {
46
- rootWindow = rootWindow.parent;
51
+ var intervalId = self.setInterval(function () {
52
+ if (rootWindow.location.protocol !== "about:") {
53
+ // reload immediately if protocol is valid
54
+ applyReload(rootWindow, intervalId);
55
+ } else {
56
+ rootWindow = rootWindow.parent;
47
57
 
48
- if (rootWindow.parent === rootWindow) {
49
- // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
50
- applyReload(rootWindow, intervalId);
51
- }
58
+ if (rootWindow.parent === rootWindow) {
59
+ // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
60
+ applyReload(rootWindow, intervalId);
52
61
  }
53
- });
54
- }
62
+ }
63
+ });
64
+ }
55
65
  }
56
66
 
57
- module.exports = reloadApp;
67
+ export default reloadApp;
@@ -1,14 +1,12 @@
1
- 'use strict';
2
1
  /* global __resourceQuery WorkerGlobalScope */
3
2
  // Send messages to the outside, so plugins can consume it.
4
-
5
3
  function sendMsg(type, data) {
6
- if (typeof self !== 'undefined' && (typeof WorkerGlobalScope === 'undefined' || !(self instanceof WorkerGlobalScope))) {
4
+ if (typeof self !== "undefined" && (typeof WorkerGlobalScope === "undefined" || !(self instanceof WorkerGlobalScope))) {
7
5
  self.postMessage({
8
6
  type: "webpack".concat(type),
9
7
  data: data
10
- }, '*');
8
+ }, "*");
11
9
  }
12
10
  }
13
11
 
14
- module.exports = sendMsg;
12
+ export default sendMsg;