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