webpack-dev-server 2.9.7 → 2.11.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/README.md +16 -10
- package/bin/webpack-dev-server.js +10 -4
- package/client/index.bundle.js +1 -1
- package/client/index.js +73 -63
- package/client/live.bundle.js +3 -3
- package/client/overlay.js +13 -15
- package/client/socket.js +15 -11
- package/client/sockjs.bundle.js +1 -1
- package/lib/Server.js +9 -1
- package/lib/optionsSchema.json +4 -0
- package/package.json +29 -22
- package/ssl/.DS_Store +0 -0
- package/client/.eslintrc +0 -7
- package/client/live.js +0 -124
- package/client/page.pug +0 -7
- package/client/sockjs.js +0 -3
- package/client/style.css +0 -58
- package/client/web_modules/jquery/index.js +0 -2
- package/client/web_modules/jquery/jquery-1.8.1.js +0 -9301
- package/client/webpack.config.js +0 -26
- package/client/webpack.sockjs.config.js +0 -14
package/client/index.js
CHANGED
|
@@ -3,28 +3,32 @@
|
|
|
3
3
|
/* global __resourceQuery WorkerGlobalScope self */
|
|
4
4
|
/* eslint prefer-destructuring: off */
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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) {
|
|
15
|
+
if (document.currentScript) {
|
|
16
|
+
return document.currentScript.getAttribute('src');
|
|
17
|
+
}
|
|
16
18
|
// Fall back to getting all scripts in the document.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (currentScript) {
|
|
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
|
-
|
|
25
|
-
|
|
28
|
+
var urlParts = void 0;
|
|
29
|
+
var hotReload = true;
|
|
26
30
|
if (typeof window !== 'undefined') {
|
|
27
|
-
|
|
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,38 +36,34 @@ 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
|
-
|
|
39
|
+
var scriptHost = getCurrentScriptSource();
|
|
36
40
|
// eslint-disable-next-line no-useless-escape
|
|
37
41
|
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
|
|
38
|
-
urlParts = url.parse(
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
68
|
type: 'webpack' + type,
|
|
69
69
|
data: data
|
|
@@ -71,27 +71,28 @@ function sendMsg(type, data) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
hot: function
|
|
76
|
-
|
|
74
|
+
var onSocketMsg = {
|
|
75
|
+
hot: function hot() {
|
|
76
|
+
_hot = true;
|
|
77
77
|
log.info('[WDS] Hot Module Replacement enabled.');
|
|
78
78
|
},
|
|
79
|
-
invalid: function
|
|
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: function
|
|
86
|
-
currentHash =
|
|
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
|
-
|
|
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
|
}
|
|
@@ -111,9 +112,9 @@ const onSocketMsg = {
|
|
|
111
112
|
log.error('[WDS] Unknown clientLogLevel \'' + level + '\'');
|
|
112
113
|
}
|
|
113
114
|
},
|
|
114
|
-
overlay: function
|
|
115
|
+
overlay: function overlay(value) {
|
|
115
116
|
if (typeof document !== 'undefined') {
|
|
116
|
-
if (typeof
|
|
117
|
+
if (typeof value === 'boolean') {
|
|
117
118
|
useWarningOverlay = false;
|
|
118
119
|
useErrorOverlay = value;
|
|
119
120
|
} else if (value) {
|
|
@@ -122,53 +123,62 @@ const onSocketMsg = {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
},
|
|
125
|
-
progress: function
|
|
126
|
+
progress: function progress(_progress) {
|
|
126
127
|
if (typeof document !== 'undefined') {
|
|
127
|
-
useProgress =
|
|
128
|
+
useProgress = _progress;
|
|
128
129
|
}
|
|
129
130
|
},
|
|
131
|
+
|
|
130
132
|
'progress-update': function progressUpdate(data) {
|
|
131
133
|
if (useProgress) log.info('[WDS] ' + data.percent + '% - ' + data.msg + '.');
|
|
132
134
|
},
|
|
133
|
-
ok: function
|
|
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: function
|
|
146
|
+
warnings: function warnings(_warnings) {
|
|
144
147
|
log.warn('[WDS] Warnings while compiling.');
|
|
145
|
-
|
|
148
|
+
var strippedWarnings = _warnings.map(function (warning) {
|
|
149
|
+
return stripAnsi(warning);
|
|
150
|
+
});
|
|
146
151
|
sendMsg('Warnings', strippedWarnings);
|
|
147
|
-
for (
|
|
148
|
-
|
|
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: function
|
|
160
|
+
errors: function errors(_errors) {
|
|
154
161
|
log.error('[WDS] Errors while compiling. Reload prevented.');
|
|
155
|
-
|
|
162
|
+
var strippedErrors = _errors.map(function (error) {
|
|
163
|
+
return stripAnsi(error);
|
|
164
|
+
});
|
|
156
165
|
sendMsg('Errors', strippedErrors);
|
|
157
|
-
for (
|
|
158
|
-
|
|
166
|
+
for (var i = 0; i < strippedErrors.length; i++) {
|
|
167
|
+
log.error(strippedErrors[i]);
|
|
168
|
+
}
|
|
169
|
+
if (useErrorOverlay) overlay.showMessage(_errors);
|
|
159
170
|
},
|
|
160
|
-
error: function
|
|
161
|
-
log.error(
|
|
171
|
+
error: function error(_error) {
|
|
172
|
+
log.error(_error);
|
|
162
173
|
},
|
|
163
|
-
close: function
|
|
174
|
+
close: function close() {
|
|
164
175
|
log.error('[WDS] Disconnected!');
|
|
165
176
|
sendMsg('Close');
|
|
166
177
|
}
|
|
167
178
|
};
|
|
168
179
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
var hostname = urlParts.hostname;
|
|
181
|
+
var protocol = urlParts.protocol;
|
|
172
182
|
|
|
173
183
|
// check ipv4 and ipv6 `all hostname`
|
|
174
184
|
if (hostname === '0.0.0.0' || hostname === '::') {
|
|
@@ -189,7 +199,7 @@ if (hostname && (self.location.protocol === 'https:' || urlParts.hostname === '0
|
|
|
189
199
|
protocol = self.location.protocol;
|
|
190
200
|
}
|
|
191
201
|
|
|
192
|
-
|
|
202
|
+
var socketUrl = url.format({
|
|
193
203
|
protocol: protocol,
|
|
194
204
|
auth: urlParts.auth,
|
|
195
205
|
hostname: hostname,
|
|
@@ -199,8 +209,8 @@ const socketUrl = url.format({
|
|
|
199
209
|
|
|
200
210
|
socket(socketUrl, onSocketMsg);
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
self.addEventListener('beforeunload', function
|
|
212
|
+
var isUnloading = false;
|
|
213
|
+
self.addEventListener('beforeunload', function () {
|
|
204
214
|
isUnloading = true;
|
|
205
215
|
});
|
|
206
216
|
|
|
@@ -208,19 +218,19 @@ function reloadApp() {
|
|
|
208
218
|
if (isUnloading || !hotReload) {
|
|
209
219
|
return;
|
|
210
220
|
}
|
|
211
|
-
if (
|
|
221
|
+
if (_hot) {
|
|
212
222
|
log.info('[WDS] App hot update...');
|
|
213
223
|
// eslint-disable-next-line global-require
|
|
214
|
-
|
|
224
|
+
var hotEmitter = require('webpack/hot/emitter');
|
|
215
225
|
hotEmitter.emit('webpackHotUpdate', currentHash);
|
|
216
226
|
if (typeof self !== 'undefined' && self.window) {
|
|
217
227
|
// broadcast update to window
|
|
218
228
|
self.postMessage('webpackHotUpdate' + currentHash, '*');
|
|
219
229
|
}
|
|
220
230
|
} else {
|
|
221
|
-
|
|
231
|
+
var rootWindow = self;
|
|
222
232
|
// use parent window for reload (in case we're in an iframe with no valid src)
|
|
223
|
-
|
|
233
|
+
var intervalId = self.setInterval(function () {
|
|
224
234
|
if (rootWindow.location.protocol !== 'about:') {
|
|
225
235
|
// reload immediately if protocol is valid
|
|
226
236
|
applyReload(rootWindow, intervalId);
|
|
@@ -239,4 +249,4 @@ function reloadApp() {
|
|
|
239
249
|
log.info('[WDS] App updated. Reloading...');
|
|
240
250
|
rootWindow.location.reload();
|
|
241
251
|
}
|
|
242
|
-
}
|
|
252
|
+
}
|