webpack-dev-server 2.10.0 → 2.11.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/client/index.js CHANGED
@@ -3,28 +3,32 @@
3
3
  /* global __resourceQuery WorkerGlobalScope self */
4
4
  /* eslint prefer-destructuring: off */
5
5
 
6
- const url = require('url');
7
- const stripAnsi = require('strip-ansi');
8
- const log = require('loglevel').getLogger('webpack-dev-server');
9
- const socket = require('./socket');
10
- const overlay = require('./overlay');
6
+ var url = require('url');
7
+ var stripAnsi = require('strip-ansi');
8
+ var log = require('loglevel').getLogger('webpack-dev-server');
9
+ var socket = require('./socket');
10
+ var overlay = require('./overlay');
11
11
 
12
12
  function getCurrentScriptSource() {
13
13
  // `document.currentScript` is the most accurate way to find the current script,
14
14
  // but is not supported in all browsers.
15
- if (document.currentScript) { return document.currentScript.getAttribute('src'); }
15
+ if (document.currentScript) {
16
+ return document.currentScript.getAttribute('src');
17
+ }
16
18
  // Fall back to getting all scripts in the document.
17
- const scriptElements = document.scripts || [];
18
- const currentScript = scriptElements[scriptElements.length - 1];
19
- if (currentScript) { return currentScript.getAttribute('src'); }
19
+ var scriptElements = document.scripts || [];
20
+ var currentScript = scriptElements[scriptElements.length - 1];
21
+ if (currentScript) {
22
+ return currentScript.getAttribute('src');
23
+ }
20
24
  // Fail as there was no script to use.
21
25
  throw new Error('[WDS] Failed to get current script source.');
22
26
  }
23
27
 
24
- let urlParts;
25
- let hotReload = true;
28
+ var urlParts = void 0;
29
+ var hotReload = true;
26
30
  if (typeof window !== 'undefined') {
27
- const qs = window.location.search.toLowerCase();
31
+ var qs = window.location.search.toLowerCase();
28
32
  hotReload = qs.indexOf('hotreload=false') === -1;
29
33
  }
30
34
  if (typeof __resourceQuery === 'string' && __resourceQuery) {
@@ -32,66 +36,63 @@ if (typeof __resourceQuery === 'string' && __resourceQuery) {
32
36
  urlParts = url.parse(__resourceQuery.substr(1));
33
37
  } else {
34
38
  // Else, get the url from the <script> this file was called with.
35
- let scriptHost = getCurrentScriptSource();
39
+ var scriptHost = getCurrentScriptSource();
36
40
  // eslint-disable-next-line no-useless-escape
37
41
  scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
38
- urlParts = url.parse((scriptHost || '/'), false, true);
42
+ urlParts = url.parse(scriptHost || '/', false, true);
39
43
  }
40
44
 
41
45
  if (!urlParts.port || urlParts.port === '0') {
42
46
  urlParts.port = self.location.port;
43
47
  }
44
48
 
45
- let hot = false;
46
- let initial = true;
47
- let currentHash = '';
48
- let useWarningOverlay = false;
49
- let useErrorOverlay = false;
50
- let useProgress = false;
49
+ var _hot = false;
50
+ var initial = true;
51
+ var currentHash = '';
52
+ var useWarningOverlay = false;
53
+ var useErrorOverlay = false;
54
+ var useProgress = false;
51
55
 
52
- const INFO = 'info';
53
- const WARNING = 'warning';
54
- const ERROR = 'error';
55
- const NONE = 'none';
56
+ var INFO = 'info';
57
+ var WARNING = 'warning';
58
+ var ERROR = 'error';
59
+ var NONE = 'none';
56
60
 
57
61
  // Set the default log level
58
62
  log.setDefaultLevel(INFO);
59
63
 
60
64
  // Send messages to the outside, so plugins can consume it.
61
65
  function sendMsg(type, data) {
62
- if (
63
- typeof self !== 'undefined' &&
64
- (typeof WorkerGlobalScope === 'undefined' ||
65
- !(self instanceof WorkerGlobalScope))
66
- ) {
66
+ if (typeof self !== 'undefined' && (typeof WorkerGlobalScope === 'undefined' || !(self instanceof WorkerGlobalScope))) {
67
67
  self.postMessage({
68
- type: `webpack${type}`,
69
- data
68
+ type: 'webpack' + type,
69
+ data: data
70
70
  }, '*');
71
71
  }
72
72
  }
73
73
 
74
- const onSocketMsg = {
75
- hot() {
76
- hot = true;
74
+ var onSocketMsg = {
75
+ hot: function hot() {
76
+ _hot = true;
77
77
  log.info('[WDS] Hot Module Replacement enabled.');
78
78
  },
79
- invalid() {
79
+ invalid: function invalid() {
80
80
  log.info('[WDS] App updated. Recompiling...');
81
81
  // fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
82
82
  if (useWarningOverlay || useErrorOverlay) overlay.clear();
83
83
  sendMsg('Invalid');
84
84
  },
85
- hash(hash) {
86
- currentHash = hash;
85
+ hash: function hash(_hash) {
86
+ currentHash = _hash;
87
87
  },
88
+
88
89
  'still-ok': function stillOk() {
89
90
  log.info('[WDS] Nothing changed.');
90
91
  if (useWarningOverlay || useErrorOverlay) overlay.clear();
91
92
  sendMsg('StillOk');
92
93
  },
93
94
  'log-level': function logLevel(level) {
94
- const hotCtx = require.context('webpack/hot', false, /^\.\/log$/);
95
+ var hotCtx = require.context('webpack/hot', false, /^\.\/log$/);
95
96
  if (hotCtx.keys().indexOf('./log') !== -1) {
96
97
  hotCtx('./log').setLogLevel(level);
97
98
  }
@@ -108,12 +109,12 @@ const onSocketMsg = {
108
109
  log.disableAll();
109
110
  break;
110
111
  default:
111
- log.error(`[WDS] Unknown clientLogLevel '${level}'`);
112
+ log.error('[WDS] Unknown clientLogLevel \'' + level + '\'');
112
113
  }
113
114
  },
114
- overlay(value) {
115
+ overlay: function overlay(value) {
115
116
  if (typeof document !== 'undefined') {
116
- if (typeof (value) === 'boolean') {
117
+ if (typeof value === 'boolean') {
117
118
  useWarningOverlay = false;
118
119
  useErrorOverlay = value;
119
120
  } else if (value) {
@@ -122,53 +123,63 @@ const onSocketMsg = {
122
123
  }
123
124
  }
124
125
  },
125
- progress(progress) {
126
+ progress: function progress(_progress) {
126
127
  if (typeof document !== 'undefined') {
127
- useProgress = progress;
128
+ useProgress = _progress;
128
129
  }
129
130
  },
131
+
130
132
  'progress-update': function progressUpdate(data) {
131
- if (useProgress) log.info(`[WDS] ${data.percent}% - ${data.msg}.`);
133
+ if (useProgress) log.info('[WDS] ' + data.percent + '% - ' + data.msg + '.');
132
134
  },
133
- ok() {
135
+ ok: function ok() {
134
136
  sendMsg('Ok');
135
137
  if (useWarningOverlay || useErrorOverlay) overlay.clear();
136
138
  if (initial) return initial = false; // eslint-disable-line no-return-assign
137
139
  reloadApp();
138
140
  },
141
+
139
142
  'content-changed': function contentChanged() {
140
143
  log.info('[WDS] Content base changed. Reloading...');
141
144
  self.location.reload();
142
145
  },
143
- warnings(warnings) {
146
+ warnings: function warnings(_warnings) {
144
147
  log.warn('[WDS] Warnings while compiling.');
145
- const strippedWarnings = warnings.map(warning => stripAnsi(warning));
148
+ var strippedWarnings = _warnings.map(function (warning) {
149
+ return stripAnsi(warning);
150
+ });
146
151
  sendMsg('Warnings', strippedWarnings);
147
- for (let i = 0; i < strippedWarnings.length; i++) { log.warn(strippedWarnings[i]); }
148
- if (useWarningOverlay) overlay.showMessage(warnings);
152
+ for (var i = 0; i < strippedWarnings.length; i++) {
153
+ log.warn(strippedWarnings[i]);
154
+ }
155
+ if (useWarningOverlay) overlay.showMessage(_warnings);
149
156
 
150
157
  if (initial) return initial = false; // eslint-disable-line no-return-assign
151
158
  reloadApp();
152
159
  },
153
- errors(errors) {
160
+ errors: function errors(_errors) {
154
161
  log.error('[WDS] Errors while compiling. Reload prevented.');
155
- const strippedErrors = errors.map(error => stripAnsi(error));
162
+ var strippedErrors = _errors.map(function (error) {
163
+ return stripAnsi(error);
164
+ });
156
165
  sendMsg('Errors', strippedErrors);
157
- for (let i = 0; i < strippedErrors.length; i++) { log.error(strippedErrors[i]); }
158
- if (useErrorOverlay) overlay.showMessage(errors);
166
+ for (var i = 0; i < strippedErrors.length; i++) {
167
+ log.error(strippedErrors[i]);
168
+ }
169
+ if (useErrorOverlay) overlay.showMessage(_errors);
170
+ initial = false;
159
171
  },
160
- error(error) {
161
- log.error(error);
172
+ error: function error(_error) {
173
+ log.error(_error);
162
174
  },
163
- close() {
175
+ close: function close() {
164
176
  log.error('[WDS] Disconnected!');
165
177
  sendMsg('Close');
166
178
  }
167
179
  };
168
180
 
169
- let hostname = urlParts.hostname;
170
- let protocol = urlParts.protocol;
171
-
181
+ var hostname = urlParts.hostname;
182
+ var protocol = urlParts.protocol;
172
183
 
173
184
  // check ipv4 and ipv6 `all hostname`
174
185
  if (hostname === '0.0.0.0' || hostname === '::') {
@@ -189,18 +200,18 @@ if (hostname && (self.location.protocol === 'https:' || urlParts.hostname === '0
189
200
  protocol = self.location.protocol;
190
201
  }
191
202
 
192
- const socketUrl = url.format({
193
- protocol,
203
+ var socketUrl = url.format({
204
+ protocol: protocol,
194
205
  auth: urlParts.auth,
195
- hostname,
206
+ hostname: hostname,
196
207
  port: urlParts.port,
197
208
  pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path
198
209
  });
199
210
 
200
211
  socket(socketUrl, onSocketMsg);
201
212
 
202
- let isUnloading = false;
203
- self.addEventListener('beforeunload', () => {
213
+ var isUnloading = false;
214
+ self.addEventListener('beforeunload', function () {
204
215
  isUnloading = true;
205
216
  });
206
217
 
@@ -208,19 +219,19 @@ function reloadApp() {
208
219
  if (isUnloading || !hotReload) {
209
220
  return;
210
221
  }
211
- if (hot) {
222
+ if (_hot) {
212
223
  log.info('[WDS] App hot update...');
213
224
  // eslint-disable-next-line global-require
214
- const hotEmitter = require('webpack/hot/emitter');
225
+ var hotEmitter = require('webpack/hot/emitter');
215
226
  hotEmitter.emit('webpackHotUpdate', currentHash);
216
227
  if (typeof self !== 'undefined' && self.window) {
217
228
  // broadcast update to window
218
- self.postMessage(`webpackHotUpdate${currentHash}`, '*');
229
+ self.postMessage('webpackHotUpdate' + currentHash, '*');
219
230
  }
220
231
  } else {
221
- let rootWindow = self;
232
+ var rootWindow = self;
222
233
  // use parent window for reload (in case we're in an iframe with no valid src)
223
- const intervalId = self.setInterval(() => {
234
+ var intervalId = self.setInterval(function () {
224
235
  if (rootWindow.location.protocol !== 'about:') {
225
236
  // reload immediately if protocol is valid
226
237
  applyReload(rootWindow, intervalId);
@@ -239,4 +250,4 @@ function reloadApp() {
239
250
  log.info('[WDS] App updated. Reloading...');
240
251
  rootWindow.location.reload();
241
252
  }
242
- }
253
+ }