webpack-dev-server 1.15.1 → 1.16.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/live.js CHANGED
@@ -1,128 +1,129 @@
1
- var $ = require("jquery");
2
- var SockJS = require("sockjs-client");
3
- var stripAnsi = require('strip-ansi');
4
- require("./style.css");
5
-
6
- var sock = null;
7
- var hot = false;
8
- var currentHash = "";
9
-
10
- var newConnection = function(handlers) {
11
- sock = new SockJS('/sockjs-node');
12
-
13
- sock.onclose = function() {
14
- handlers.close();
15
-
16
- // Try to reconnect.
17
- sock = null;
18
- setTimeout(function() {
19
- newConnection(handlers);
20
- }, 2000);
21
- };
22
-
23
- sock.onmessage = function(e) {
24
- // This assumes that all data sent via the websocket is JSON.
25
- var msg = JSON.parse(e.data);
26
- handlers[msg.type](msg.data);
27
- };
28
- };
29
-
30
- $(function() {
31
- var body = $("body").html(require("./page.jade")());
32
- var status = $("#status");
33
- var okness = $("#okness");
34
- var $errors = $("#errors");
35
- var iframe = $("#iframe");
36
- var header = $(".header");
37
-
38
- var contentPage = window.location.pathname.substr("/webpack-dev-server".length) + window.location.search;
39
-
40
- status.text("Connecting to sockjs server...");
41
- $errors.hide(); iframe.hide();
42
- header.css({borderColor: "#96b5b4"});
43
-
44
- var onSocketMsg = {
45
- hot: function() {
46
- hot = true;
47
- iframe.attr("src", contentPage + window.location.hash);
48
- },
49
- invalid: function() {
50
- okness.text("");
51
- status.text("App updated. Recompiling...");
52
- header.css({borderColor: "#96b5b4"});
53
- $errors.hide(); if(!hot) iframe.hide();
54
- },
55
- hash: function(hash) {
56
- currentHash = hash;
57
- },
58
- "still-ok": function() {
59
- okness.text("");
60
- status.text("App ready.");
61
- header.css({borderColor: ""});
62
- $errors.hide(); if(!hot) iframe.show();
63
- },
64
- ok: function() {
65
- okness.text("");
66
- $errors.hide();
67
- reloadApp();
68
- },
69
- warnings: function(warnings) {
70
- okness.text("Warnings while compiling.");
71
- $errors.hide();
72
- reloadApp();
73
- },
74
- errors: function(errors) {
75
- status.text("App updated with errors. No reload!");
76
- okness.text("Errors while compiling.");
77
- $errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
78
- header.css({borderColor: "#ebcb8b"});
79
- $errors.show(); iframe.hide();
80
- },
81
- "proxy-error": function(errors) {
82
- status.text("Could not proxy to content base target!");
83
- okness.text("Proxy error.");
84
- $errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
85
- header.css({borderColor: "#ebcb8b"});
86
- $errors.show(); iframe.hide();
87
- },
88
- close: function() {
89
- status.text("");
90
- okness.text("Disconnected.");
91
- $errors.text("\n\n\n Lost connection to webpack-dev-server.\n Please restart the server to reestablish connection...\n\n\n\n");
92
- header.css({borderColor: "#ebcb8b"});
93
- $errors.show(); iframe.hide();
94
- }
95
- };
96
-
97
- newConnection(onSocketMsg);
98
-
99
- iframe.load(function() {
100
- status.text("App ready.");
101
- header.css({borderColor: ""});
102
- iframe.show();
103
- });
104
-
105
- function reloadApp() {
106
- if(hot) {
107
- status.text("App hot update.");
108
- try {
109
- iframe[0].contentWindow.postMessage("webpackHotUpdate" + currentHash, "*");
110
- } catch(e) {
111
- console.warn(e);
112
- }
113
- iframe.show();
114
- } else {
115
- status.text("App updated. Reloading app...");
116
- header.css({borderColor: "#96b5b4"});
117
- try {
118
- var old = iframe[0].contentWindow.location + "";
119
- if(old.indexOf("about") == 0) old = null;
120
- iframe.attr("src", old || (contentPage + window.location.hash));
121
- old && iframe[0].contentWindow.location.reload();
122
- } catch(e) {
123
- iframe.attr("src", contentPage + window.location.hash);
124
- }
125
- }
126
- }
127
-
128
- });
1
+ var $ = require("jquery");
2
+ var stripAnsi = require('strip-ansi');
3
+ var socket = require('./socket');
4
+ require("./style.css");
5
+
6
+ var hot = false;
7
+ var currentHash = "";
8
+
9
+ $(function() {
10
+ $("body").html(require("./page.jade")());
11
+ var status = $("#status");
12
+ var okness = $("#okness");
13
+ var $errors = $("#errors");
14
+ var iframe = $("#iframe");
15
+ var header = $(".header");
16
+
17
+ var contentPage = window.location.pathname.substr("/webpack-dev-server".length) + window.location.search;
18
+
19
+ status.text("Connecting to sockjs server...");
20
+ $errors.hide();
21
+ iframe.hide();
22
+ header.css({
23
+ borderColor: "#96b5b4"
24
+ });
25
+
26
+ var onSocketMsg = {
27
+ hot: function() {
28
+ hot = true;
29
+ iframe.attr("src", contentPage + window.location.hash);
30
+ },
31
+ invalid: function() {
32
+ okness.text("");
33
+ status.text("App updated. Recompiling...");
34
+ header.css({
35
+ borderColor: "#96b5b4"
36
+ });
37
+ $errors.hide();
38
+ if(!hot) iframe.hide();
39
+ },
40
+ hash: function(hash) {
41
+ currentHash = hash;
42
+ },
43
+ "still-ok": function() {
44
+ okness.text("");
45
+ status.text("App ready.");
46
+ header.css({
47
+ borderColor: ""
48
+ });
49
+ $errors.hide();
50
+ if(!hot) iframe.show();
51
+ },
52
+ ok: function() {
53
+ okness.text("");
54
+ $errors.hide();
55
+ reloadApp();
56
+ },
57
+ warnings: function() {
58
+ okness.text("Warnings while compiling.");
59
+ $errors.hide();
60
+ reloadApp();
61
+ },
62
+ errors: function(errors) {
63
+ status.text("App updated with errors. No reload!");
64
+ okness.text("Errors while compiling.");
65
+ $errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
66
+ header.css({
67
+ borderColor: "#ebcb8b"
68
+ });
69
+ $errors.show();
70
+ iframe.hide();
71
+ },
72
+ "proxy-error": function(errors) {
73
+ status.text("Could not proxy to content base target!");
74
+ okness.text("Proxy error.");
75
+ $errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
76
+ header.css({
77
+ borderColor: "#ebcb8b"
78
+ });
79
+ $errors.show();
80
+ iframe.hide();
81
+ },
82
+ close: function() {
83
+ status.text("");
84
+ okness.text("Disconnected.");
85
+ $errors.text("\n\n\n Lost connection to webpack-dev-server.\n Please restart the server to reestablish connection...\n\n\n\n");
86
+ header.css({
87
+ borderColor: "#ebcb8b"
88
+ });
89
+ $errors.show();
90
+ iframe.hide();
91
+ }
92
+ };
93
+
94
+ socket("/sockjs-node", onSocketMsg);
95
+
96
+ iframe.load(function() {
97
+ status.text("App ready.");
98
+ header.css({
99
+ borderColor: ""
100
+ });
101
+ iframe.show();
102
+ });
103
+
104
+ function reloadApp() {
105
+ if(hot) {
106
+ status.text("App hot update.");
107
+ try {
108
+ iframe[0].contentWindow.postMessage("webpackHotUpdate" + currentHash, "*");
109
+ } catch(e) {
110
+ console.warn(e);
111
+ }
112
+ iframe.show();
113
+ } else {
114
+ status.text("App updated. Reloading app...");
115
+ header.css({
116
+ borderColor: "#96b5b4"
117
+ });
118
+ try {
119
+ var old = iframe[0].contentWindow.location + "";
120
+ if(old.indexOf("about") == 0) old = null;
121
+ iframe.attr("src", old || (contentPage + window.location.hash));
122
+ old && iframe[0].contentWindow.location.reload();
123
+ } catch(e) {
124
+ iframe.attr("src", contentPage + window.location.hash);
125
+ }
126
+ }
127
+ }
128
+
129
+ });
package/client/page.jade CHANGED
@@ -1,7 +1,7 @@
1
- .header
2
- span#okness
3
- = " "
4
- span#status
5
- pre#errors
6
- #warnings
7
- iframe#iframe(src="javascript:;" allowfullscreen)
1
+ .header
2
+ span#okness
3
+ = " "
4
+ span#status
5
+ pre#errors
6
+ #warnings
7
+ iframe#iframe(src="javascript:;" allowfullscreen)
@@ -0,0 +1,41 @@
1
+ var SockJS = require("sockjs-client");
2
+
3
+ var retries = 0;
4
+ var sock = null;
5
+
6
+ function socket(url, handlers) {
7
+ sock = new SockJS(url);
8
+
9
+ sock.onopen = function() {
10
+ retries = 0;
11
+ }
12
+
13
+ sock.onclose = function() {
14
+ if(retries === 0)
15
+ handlers.close();
16
+
17
+ // Try to reconnect.
18
+ sock = null;
19
+
20
+ // After 10 retries stop trying, to prevent logspam.
21
+ if(retries <= 10) {
22
+ // Exponentially increase timeout to reconnect.
23
+ // Respectfully copied from the package `got`.
24
+ var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
25
+ retries += 1;
26
+
27
+ setTimeout(function() {
28
+ socket(url, handlers);
29
+ }, retryInMs);
30
+ }
31
+ };
32
+
33
+ sock.onmessage = function(e) {
34
+ // This assumes that all data sent via the websocket is JSON.
35
+ var msg = JSON.parse(e.data);
36
+ if(handlers[msg.type])
37
+ handlers[msg.type](msg.data);
38
+ };
39
+ }
40
+
41
+ module.exports = socket;
package/client/style.css CHANGED
@@ -1,58 +1,58 @@
1
- *,
2
- *:before,
3
- *:after {
4
- -webkit-box-sizing: border-box;
5
- -moz-box-sizing: border-box;
6
- box-sizing: border-box;
7
- }
8
-
9
- body,
10
- html {
11
- margin: 0;
12
- padding: 0;
13
- height: 100%;
14
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
15
- }
16
-
17
- .header {
18
- width: 100%;
19
- height: 30px;
20
- padding: 0 10px;
21
- border-left: 10px solid #a3be8c;
22
- font-size: 12px;
23
- line-height: 30px;
24
- color: #eff1f5;
25
- background: #343d46;
26
- overflow: hidden;
27
- }
28
-
29
- #iframe {
30
- position: absolute;
31
- top: 30px;
32
- right: 0;
33
- bottom: 0;
34
- left: 0;
35
- width: 100%;
36
- height: -webkit-calc(100% - 30px);
37
- height: -moz-calc(100% - 30px);
38
- height: -ms-calc(100% - 30px);
39
- height: -o-calc(100% - 30px);
40
- height: calc(100% - 30px);
41
- border: 0;
42
- }
43
-
44
- #errors {
45
- width: 100%;
46
- margin: 0;
47
- padding: 10px;
48
- font-family: monospace;
49
- font-size: 14px;
50
- line-height: 1.4;
51
- color: #eff1f5;
52
- background: #bf616a;
53
- overflow: auto;
54
- }
55
-
56
- #okness {
57
- font-weight: bold;
58
- }
1
+ *,
2
+ *:before,
3
+ *:after {
4
+ -webkit-box-sizing: border-box;
5
+ -moz-box-sizing: border-box;
6
+ box-sizing: border-box;
7
+ }
8
+
9
+ body,
10
+ html {
11
+ margin: 0;
12
+ padding: 0;
13
+ height: 100%;
14
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
15
+ }
16
+
17
+ .header {
18
+ width: 100%;
19
+ height: 30px;
20
+ padding: 0 10px;
21
+ border-left: 10px solid #a3be8c;
22
+ font-size: 12px;
23
+ line-height: 30px;
24
+ color: #eff1f5;
25
+ background: #343d46;
26
+ overflow: hidden;
27
+ }
28
+
29
+ #iframe {
30
+ position: absolute;
31
+ top: 30px;
32
+ right: 0;
33
+ bottom: 0;
34
+ left: 0;
35
+ width: 100%;
36
+ height: -webkit-calc(100% - 30px);
37
+ height: -moz-calc(100% - 30px);
38
+ height: -ms-calc(100% - 30px);
39
+ height: -o-calc(100% - 30px);
40
+ height: calc(100% - 30px);
41
+ border: 0;
42
+ }
43
+
44
+ #errors {
45
+ width: 100%;
46
+ margin: 0;
47
+ padding: 10px;
48
+ font-family: monospace;
49
+ font-size: 14px;
50
+ line-height: 1.4;
51
+ color: #eff1f5;
52
+ background: #bf616a;
53
+ overflow: auto;
54
+ }
55
+
56
+ #okness {
57
+ font-weight: bold;
58
+ }
@@ -1,2 +1,2 @@
1
- require("./jquery-1.8.1");
1
+ require("./jquery-1.8.1");
2
2
  module.exports = jQuery;