Skip to content

Commit 639f2b0

Browse files
committed
merging in webpack/master to wolfeidau/add_public_host_flag
2 parents 99c6d99 + 33ebd1f commit 639f2b0

File tree

12 files changed

+431
-217
lines changed

12 files changed

+431
-217
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*.js]
4+
indent_style=tab
5+
trim_trailing_whitespace=true

.eslintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"plugins": [
6+
"nodeca"
7+
],
8+
"rules": {
9+
"strict": 0,
10+
"camelcase": 0,
11+
"curly": 0,
12+
"indent": [0, "tab"],
13+
"nodeca/indent": [2, "tabs", 1],
14+
"eol-last": 2,
15+
"no-shadow": 0,
16+
"no-redeclare": 2,
17+
"no-extra-bind": 2,
18+
"no-empty": 0,
19+
"no-process-exit": 2,
20+
"no-underscore-dangle": 0,
21+
"no-use-before-define": 0,
22+
"no-unused-vars": 0,
23+
"consistent-return": 0,
24+
"no-inner-declarations": 2,
25+
"no-loop-func": 2,
26+
"space-before-function-paren": [2, "never"]
27+
}
28+
}

.jsbeautifyrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"js": {
3+
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
4+
"brace_style": "collapse",
5+
"break_chained_methods": false,
6+
"e4x": true,
7+
"eval_code": false,
8+
"end_with_newline": true,
9+
"indent_char": "\t",
10+
"indent_level": 0,
11+
"indent_size": 1,
12+
"indent_with_tabs": true,
13+
"jslint_happy": false,
14+
"jslint_happy_align_switch_case": true,
15+
"space_after_anon_function": false,
16+
"keep_array_indentation": false,
17+
"keep_function_indentation": false,
18+
"max_preserve_newlines": 2,
19+
"preserve_newlines": true,
20+
"space_before_conditional": false,
21+
"space_in_paren": false,
22+
"unescape_strings": false,
23+
"wrap_line_length": 0
24+
}
25+
}

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- node
5+
script: npm run travis

bin/webpack-dev-server.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var path = require("path");
44
var url = require("url");
5+
var open = require("open");
56
var fs = require("fs");
67

78
// Local version replaces global one
@@ -17,44 +18,50 @@ var webpack = require("webpack");
1718

1819
var optimist = require("optimist")
1920

20-
.usage("webpack-dev-server " + require("../package.json").version + "\n" +
21-
"Usage: http://webpack.github.io/docs/webpack-dev-server.html")
21+
.usage("webpack-dev-server " + require("../package.json").version + "\n" +
22+
"Usage: http://webpack.github.io/docs/webpack-dev-server.html")
2223

23-
.boolean("lazy").describe("lazy")
24+
.boolean("lazy").describe("lazy")
2425

25-
.boolean("info").describe("info").default("info", true)
26+
.boolean("stdin").describe("stdin", "close when stdin ends")
2627

27-
.boolean("quiet").describe("quiet")
28+
.boolean("info").describe("info").default("info", true)
2829

29-
.boolean("inline").describe("inline", "Inline the webpack-dev-server logic into the bundle.")
30+
.boolean("quiet").describe("quiet")
3031

31-
.boolean("https").describe("https")
32+
.boolean("inline").describe("inline", "Inline the webpack-dev-server logic into the bundle.")
3233

33-
.string("key").describe("key", "Path to a SSL key.")
34+
.boolean("https").describe("https")
3435

35-
.string("cert").describe("cert", "Path to a SSL certificate.")
36+
.string("key").describe("key", "Path to a SSL key.")
3637

37-
.string("cacert").describe("cacert", "Path to a SSL CA certificate.")
38+
.string("cert").describe("cert", "Path to a SSL certificate.")
3839

39-
.string("content-base").describe("content-base", "A directory or URL to serve HTML content from.")
40+
.string("cacert").describe("cacert", "Path to a SSL CA certificate.")
4041

41-
.string("content-base-target").describe("content-base-target", "Proxy requests to this target.")
42+
.string("content-base").describe("content-base", "A directory or URL to serve HTML content from.")
4243

43-
.boolean("history-api-fallback").describe("history-api-fallback", "Fallback to /index.html for Single Page Applications.")
44+
.string("content-base-target").describe("content-base-target", "Proxy requests to this target.")
4445

45-
.boolean("compress").describe("compress", "enable gzip compression")
46+
.boolean("history-api-fallback").describe("history-api-fallback", "Fallback to /index.html for Single Page Applications.")
4647

47-
.describe("port", "The port").default("port", 8080)
48+
.boolean("compress").describe("compress", "enable gzip compression")
4849

49-
.describe("public", "The public hostname/ip address of the server")
50+
.boolean("open").describe("open", "Open default browser")
5051

51-
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");
52+
.describe("port", "The port").default("port", 8080)
53+
54+
.describe("public", "The public hostname/ip address of the server")
55+
56+
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");
5257

5358
require("webpack/bin/config-optimist")(optimist);
5459

5560
var argv = optimist.argv;
5661

57-
var wpOpt = require("webpack/bin/convert-argv")(optimist, argv, { outputFilename: "/bundle.js" });
62+
var wpOpt = require("webpack/bin/convert-argv")(optimist, argv, {
63+
outputFilename: "/bundle.js"
64+
});
5865
var firstWpOpt = Array.isArray(wpOpt) ? wpOpt[0] : wpOpt;
5966

6067
var options = wpOpt.devServer || firstWpOpt.devServer || {};
@@ -84,6 +91,14 @@ if(!options.filename)
8491

8592
if(!options.watchOptions)
8693
options.watchOptions = firstWpOpt.watchOptions;
94+
95+
if(argv["stdin"]) {
96+
process.stdin.on('end', function() {
97+
process.exit(0);
98+
});
99+
process.stdin.resume();
100+
}
101+
87102
if(!options.watchDelay && !options.watchOptions) // TODO remove in next major version
88103
options.watchDelay = firstWpOpt.watchDelay;
89104

@@ -97,7 +112,9 @@ if(argv["content-base"]) {
97112
else if(!/^(https?:)?\/\//.test(options.contentBase))
98113
options.contentBase = path.resolve(options.contentBase);
99114
} else if(argv["content-base-target"]) {
100-
options.contentBase = { target: argv["content-base-target"] };
115+
options.contentBase = {
116+
target: argv["content-base-target"]
117+
};
101118
} else if(!options.contentBase) {
102119
options.contentBase = process.cwd();
103120
}
@@ -142,6 +159,9 @@ if(argv["history-api-fallback"])
142159
if(argv["compress"])
143160
options.compress = true;
144161

162+
if(argv["open"])
163+
options.open = true;
164+
145165
var protocol = options.https ? "https" : "http";
146166

147167
if(options.inline) {
@@ -161,16 +181,19 @@ if(options.inline) {
161181
}
162182

163183
new Server(webpack(wpOpt), options).listen(options.port, options.host, function(err) {
184+
var uri = protocol + "://" + options.host + ":" + options.port + "/";
185+
if(!options.inline)
186+
uri += "webpack-dev-server/";
187+
164188
if(err) throw err;
165-
if(options.inline)
166-
console.log(protocol + "://" + options.host + ":" + options.port + "/");
167-
else
168-
console.log(protocol + "://" + options.host + ":" + options.port + "/webpack-dev-server/");
189+
console.log(uri);
169190
console.log("webpack result is served from " + options.publicPath);
170191
if(typeof options.contentBase === "object")
171192
console.log("requests are proxied to " + options.contentBase.target);
172193
else
173194
console.log("content is served from " + options.contentBase);
174195
if(options.historyApiFallback)
175196
console.log("404s will fallback to %s", options.historyApiFallback.index || "/index.html");
197+
if(options.open)
198+
open(uri);
176199
});

client/index.js

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,89 @@
11
var url = require('url');
2-
var io = require("socket.io-client");
2+
var SockJS = require("sockjs-client");
33
var stripAnsi = require('strip-ansi');
44
var scriptElements = document.getElementsByTagName("script");
5+
var scriptHost = scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
56

7+
// If this bundle is inlined, use the resource query to get the correct url.
8+
// Else, get the url from the <script> this file was called with.
69
var urlParts = url.parse(typeof __resourceQuery === "string" && __resourceQuery ?
710
__resourceQuery.substr(1) :
8-
scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "")
9-
);
10-
11-
io = io.connect(
12-
url.format({
13-
protocol: urlParts.protocol,
14-
auth: urlParts.auth,
15-
hostname: (urlParts.hostname === '0.0.0.0') ? window.location.hostname : urlParts.hostname,
16-
port: urlParts.port
17-
}), {
18-
path: urlParts.path === '/' ? null : urlParts.path
19-
}
11+
(scriptHost ? scriptHost : "/"), false, true
2012
);
2113

14+
var sock = null;
2215
var hot = false;
2316
var initial = true;
2417
var currentHash = "";
2518

26-
io.on("hot", function() {
27-
hot = true;
28-
console.log("[WDS] Hot Module Replacement enabled.");
29-
});
30-
31-
io.on("invalid", function() {
32-
console.log("[WDS] App updated. Recompiling...");
33-
});
34-
35-
io.on("hash", function(hash) {
36-
currentHash = hash;
37-
});
38-
39-
io.on("still-ok", function() {
40-
console.log("[WDS] Nothing changed.")
41-
});
19+
var onSocketMsg = {
20+
hot: function() {
21+
hot = true;
22+
console.log("[WDS] Hot Module Replacement enabled.");
23+
},
24+
invalid: function() {
25+
console.log("[WDS] App updated. Recompiling...");
26+
},
27+
hash: function(hash) {
28+
currentHash = hash;
29+
},
30+
"still-ok": function() {
31+
console.log("[WDS] Nothing changed.")
32+
},
33+
ok: function() {
34+
if(initial) return initial = false;
35+
reloadApp();
36+
},
37+
warnings: function(warnings) {
38+
console.log("[WDS] Warnings while compiling.");
39+
for(var i = 0; i < warnings.length; i++)
40+
console.warn(stripAnsi(warnings[i]));
41+
if(initial) return initial = false;
42+
reloadApp();
43+
},
44+
errors: function(errors) {
45+
console.log("[WDS] Errors while compiling.");
46+
for(var i = 0; i < errors.length; i++)
47+
console.error(stripAnsi(errors[i]));
48+
if(initial) return initial = false;
49+
reloadApp();
50+
},
51+
"proxy-error": function(errors) {
52+
console.log("[WDS] Proxy error.");
53+
for(var i = 0; i < errors.length; i++)
54+
console.error(stripAnsi(errors[i]));
55+
if(initial) return initial = false;
56+
reloadApp();
57+
}
58+
};
4259

43-
io.on("ok", function() {
44-
if(initial) return initial = false;
45-
reloadApp();
46-
});
60+
var newConnection = function() {
61+
sock = new SockJS(url.format({
62+
protocol: urlParts.protocol,
63+
auth: urlParts.auth,
64+
hostname: (urlParts.hostname === '0.0.0.0') ? window.location.hostname : urlParts.hostname,
65+
port: urlParts.port,
66+
pathname: urlParts.path == null || urlParts.path === '/' ? "/sockjs-node" : urlParts.path
67+
}));
4768

48-
io.on("warnings", function(warnings) {
49-
console.log("[WDS] Warnings while compiling.");
50-
for(var i = 0; i < warnings.length; i++)
51-
console.warn(stripAnsi(warnings[i]));
52-
if(initial) return initial = false;
53-
reloadApp();
54-
});
69+
sock.onclose = function() {
70+
console.error("[WDS] Disconnected!");
5571

56-
io.on("errors", function(errors) {
57-
console.log("[WDS] Errors while compiling.");
58-
for(var i = 0; i < errors.length; i++)
59-
console.error(stripAnsi(errors[i]));
60-
if(initial) return initial = false;
61-
reloadApp();
62-
});
72+
// Try to reconnect.
73+
sock = null;
74+
setTimeout(function () {
75+
newConnection();
76+
}, 2000);
77+
};
6378

64-
io.on("proxy-error", function(errors) {
65-
console.log("[WDS] Proxy error.");
66-
for(var i = 0; i < errors.length; i++)
67-
console.error(stripAnsi(errors[i]));
68-
if(initial) return initial = false;
69-
reloadApp();
70-
});
79+
sock.onmessage = function(e) {
80+
// This assumes that all data sent via the websocket is JSON.
81+
var msg = JSON.parse(e.data);
82+
onSocketMsg[msg.type](msg.data);
83+
};
84+
};
7185

72-
io.on("disconnect", function() {
73-
console.error("[WDS] Disconnected!");
74-
});
86+
newConnection();
7587

7688
function reloadApp() {
7789
if(hot) {

client/live.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/><script type="text/javascript" charset="utf-8" src="/__webpack_dev_server__/live.bundle.js"></script></head><body></body></html>
1+
<!DOCTYPE html><html><head><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/><script type="text/javascript" charset="utf-8" src="/__webpack_dev_server__/live.bundle.js"></script></head><body></body></html>

0 commit comments

Comments
 (0)