webpack-dev-server 2.5.0 → 2.7.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/LICENSE +20 -20
- package/README.md +86 -86
- package/bin/webpack-dev-server.js +40 -15
- package/client/index.bundle.js +1 -1
- package/client/index.js +204 -188
- package/client/live.bundle.js +2 -2
- package/client/live.html +1 -1
- package/client/live.js +119 -119
- package/client/overlay.js +126 -126
- package/client/page.pug +7 -7
- package/client/socket.js +41 -41
- package/client/sockjs.bundle.js +1 -1
- package/client/sockjs.js +1 -1
- package/client/style.css +58 -58
- package/client/web_modules/jquery/index.js +1 -1
- package/client/web_modules/jquery/jquery-1.8.1.js +9301 -9301
- package/client/webpack.config.js +19 -19
- package/client/webpack.sockjs.config.js +6 -6
- package/lib/OptionsValidationError.js +159 -159
- package/lib/Server.js +603 -599
- package/lib/optionsSchema.json +312 -312
- package/lib/util/addDevServerEntrypoints.js +26 -26
- package/lib/util/createDomain.js +14 -14
- package/package.json +7 -5
package/client/index.js
CHANGED
|
@@ -1,188 +1,204 @@
|
|
|
1
|
-
/* global __resourceQuery WorkerGlobalScope */
|
|
2
|
-
var url = require("url");
|
|
3
|
-
var stripAnsi = require("strip-ansi");
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
scriptHost =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var useWarningOverlay = false;
|
|
37
|
-
var useErrorOverlay = false;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
typeof
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if(useWarningOverlay) overlay.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
protocol
|
|
159
|
-
|
|
160
|
-
hostname
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
1
|
+
/* global __resourceQuery WorkerGlobalScope */
|
|
2
|
+
var url = require("url");
|
|
3
|
+
var stripAnsi = require("strip-ansi");
|
|
4
|
+
var log = require("loglevel")
|
|
5
|
+
var socket = require("./socket");
|
|
6
|
+
var overlay = require("./overlay");
|
|
7
|
+
|
|
8
|
+
function getCurrentScriptSource() {
|
|
9
|
+
// `document.currentScript` is the most accurate way to find the current script,
|
|
10
|
+
// but is not supported in all browsers.
|
|
11
|
+
if(document.currentScript)
|
|
12
|
+
return document.currentScript.getAttribute("src");
|
|
13
|
+
// Fall back to getting all scripts in the document.
|
|
14
|
+
var scriptElements = document.scripts || [];
|
|
15
|
+
var currentScript = scriptElements[scriptElements.length - 1];
|
|
16
|
+
if(currentScript)
|
|
17
|
+
return currentScript.getAttribute("src");
|
|
18
|
+
// Fail as there was no script to use.
|
|
19
|
+
throw new Error("[WDS] Failed to get current script source");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var urlParts;
|
|
23
|
+
if(typeof __resourceQuery === "string" && __resourceQuery) {
|
|
24
|
+
// If this bundle is inlined, use the resource query to get the correct url.
|
|
25
|
+
urlParts = url.parse(__resourceQuery.substr(1));
|
|
26
|
+
} else {
|
|
27
|
+
// Else, get the url from the <script> this file was called with.
|
|
28
|
+
var scriptHost = getCurrentScriptSource();
|
|
29
|
+
scriptHost = scriptHost.replace(/\/[^\/]+$/, "");
|
|
30
|
+
urlParts = url.parse((scriptHost ? scriptHost : "/"), false, true);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var hot = false;
|
|
34
|
+
var initial = true;
|
|
35
|
+
var currentHash = "";
|
|
36
|
+
var useWarningOverlay = false;
|
|
37
|
+
var useErrorOverlay = false;
|
|
38
|
+
|
|
39
|
+
var INFO = "info";
|
|
40
|
+
var WARNING = "warning";
|
|
41
|
+
var ERROR = "error";
|
|
42
|
+
var NONE = "none";
|
|
43
|
+
|
|
44
|
+
// Set the default log level
|
|
45
|
+
log.setDefaultLevel(INFO);
|
|
46
|
+
|
|
47
|
+
// Send messages to the outside, so plugins can consume it.
|
|
48
|
+
function sendMsg(type, data) {
|
|
49
|
+
if(
|
|
50
|
+
typeof self !== "undefined" &&
|
|
51
|
+
(typeof WorkerGlobalScope === "undefined" ||
|
|
52
|
+
!(self instanceof WorkerGlobalScope))
|
|
53
|
+
) {
|
|
54
|
+
self.postMessage({
|
|
55
|
+
type: "webpack" + type,
|
|
56
|
+
data: data
|
|
57
|
+
}, "*");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var onSocketMsg = {
|
|
62
|
+
hot: function() {
|
|
63
|
+
hot = true;
|
|
64
|
+
log.info("[WDS] Hot Module Replacement enabled.");
|
|
65
|
+
},
|
|
66
|
+
invalid: function() {
|
|
67
|
+
log.info("[WDS] App updated. Recompiling...");
|
|
68
|
+
sendMsg("Invalid");
|
|
69
|
+
},
|
|
70
|
+
hash: function(hash) {
|
|
71
|
+
currentHash = hash;
|
|
72
|
+
},
|
|
73
|
+
"still-ok": function() {
|
|
74
|
+
log.info("[WDS] Nothing changed.")
|
|
75
|
+
if(useWarningOverlay || useErrorOverlay) overlay.clear();
|
|
76
|
+
sendMsg("StillOk");
|
|
77
|
+
},
|
|
78
|
+
"log-level": function(level) {
|
|
79
|
+
var hotCtx = require.context("webpack/hot", false, /^\.\/log$/);
|
|
80
|
+
if(hotCtx.keys().length > 0) {
|
|
81
|
+
hotCtx("./log").setLogLevel(level);
|
|
82
|
+
}
|
|
83
|
+
switch(level) {
|
|
84
|
+
case INFO:
|
|
85
|
+
case ERROR:
|
|
86
|
+
log.setLevel(level);
|
|
87
|
+
break;
|
|
88
|
+
case WARNING:
|
|
89
|
+
log.setLevel("warn"); // loglevel's warning name is different from webpack's
|
|
90
|
+
break;
|
|
91
|
+
case NONE:
|
|
92
|
+
log.disableAll();
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
log.error("[WDS] Unknown clientLogLevel '" + level + "'");
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"overlay": function(overlay) {
|
|
99
|
+
if(typeof document !== "undefined") {
|
|
100
|
+
if(typeof(overlay) === "boolean") {
|
|
101
|
+
useWarningOverlay = false;
|
|
102
|
+
useErrorOverlay = overlay;
|
|
103
|
+
} else if(overlay) {
|
|
104
|
+
useWarningOverlay = overlay.warnings;
|
|
105
|
+
useErrorOverlay = overlay.errors;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
ok: function() {
|
|
110
|
+
sendMsg("Ok");
|
|
111
|
+
if(useWarningOverlay || useErrorOverlay) overlay.clear();
|
|
112
|
+
if(initial) return initial = false;
|
|
113
|
+
reloadApp();
|
|
114
|
+
},
|
|
115
|
+
"content-changed": function() {
|
|
116
|
+
log.info("[WDS] Content base changed. Reloading...")
|
|
117
|
+
self.location.reload();
|
|
118
|
+
},
|
|
119
|
+
warnings: function(warnings) {
|
|
120
|
+
log.warn("[WDS] Warnings while compiling.");
|
|
121
|
+
var strippedWarnings = warnings.map(function(warning) {
|
|
122
|
+
return stripAnsi(warning);
|
|
123
|
+
});
|
|
124
|
+
sendMsg("Warnings", strippedWarnings);
|
|
125
|
+
for(var i = 0; i < strippedWarnings.length; i++)
|
|
126
|
+
log.warn(strippedWarnings[i]);
|
|
127
|
+
if(useWarningOverlay) overlay.showMessage(warnings);
|
|
128
|
+
|
|
129
|
+
if(initial) return initial = false;
|
|
130
|
+
reloadApp();
|
|
131
|
+
},
|
|
132
|
+
errors: function(errors) {
|
|
133
|
+
log.error("[WDS] Errors while compiling. Reload prevented.");
|
|
134
|
+
var strippedErrors = errors.map(function(error) {
|
|
135
|
+
return stripAnsi(error);
|
|
136
|
+
});
|
|
137
|
+
sendMsg("Errors", strippedErrors);
|
|
138
|
+
for(var i = 0; i < strippedErrors.length; i++)
|
|
139
|
+
log.error(strippedErrors[i]);
|
|
140
|
+
if(useErrorOverlay) overlay.showMessage(errors);
|
|
141
|
+
},
|
|
142
|
+
error: function(error) {
|
|
143
|
+
log.error(error);
|
|
144
|
+
},
|
|
145
|
+
close: function() {
|
|
146
|
+
log.error("[WDS] Disconnected!");
|
|
147
|
+
sendMsg("Close");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
var hostname = urlParts.hostname;
|
|
152
|
+
var protocol = urlParts.protocol;
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
//check ipv4 and ipv6 `all hostname`
|
|
156
|
+
if(hostname === "0.0.0.0" || hostname === "::") {
|
|
157
|
+
// why do we need this check?
|
|
158
|
+
// hostname n/a for file protocol (example, when using electron, ionic)
|
|
159
|
+
// see: https://github.com/webpack/webpack-dev-server/pull/384
|
|
160
|
+
if(self.location.hostname && !!~self.location.protocol.indexOf("http")) {
|
|
161
|
+
hostname = self.location.hostname;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// `hostname` can be empty when the script path is relative. In that case, specifying
|
|
166
|
+
// a protocol would result in an invalid URL.
|
|
167
|
+
// When https is used in the app, secure websockets are always necessary
|
|
168
|
+
// because the browser doesn't accept non-secure websockets.
|
|
169
|
+
if(hostname && (self.location.protocol === "https:" || urlParts.hostname === "0.0.0.0")) {
|
|
170
|
+
protocol = self.location.protocol;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var socketUrl = url.format({
|
|
174
|
+
protocol: protocol,
|
|
175
|
+
auth: urlParts.auth,
|
|
176
|
+
hostname: hostname,
|
|
177
|
+
port: (urlParts.port === "0") ? self.location.port : urlParts.port,
|
|
178
|
+
pathname: urlParts.path == null || urlParts.path === "/" ? "/sockjs-node" : urlParts.path
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
socket(socketUrl, onSocketMsg);
|
|
182
|
+
|
|
183
|
+
var isUnloading = false;
|
|
184
|
+
self.addEventListener("beforeunload", function() {
|
|
185
|
+
isUnloading = true;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
function reloadApp() {
|
|
189
|
+
if(isUnloading) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if(hot) {
|
|
193
|
+
log.info("[WDS] App hot update...");
|
|
194
|
+
var hotEmitter = require("webpack/hot/emitter");
|
|
195
|
+
hotEmitter.emit("webpackHotUpdate", currentHash);
|
|
196
|
+
if(typeof self !== "undefined" && self.window) {
|
|
197
|
+
// broadcast update to window
|
|
198
|
+
self.postMessage("webpackHotUpdate" + currentHash, "*");
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
log.info("[WDS] App updated. Reloading...");
|
|
202
|
+
self.location.reload();
|
|
203
|
+
}
|
|
204
|
+
}
|