Skip to content

Commit 7e2e8f8

Browse files
committed
Merge branch 'elliottsj-web-worker-hmr'
2 parents 802dd7c + 6e75a44 commit 7e2e8f8

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

client/index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
var url = require('url');
22
var SockJS = require("sockjs-client");
33
var stripAnsi = require('strip-ansi');
4-
var scriptElements = document.getElementsByTagName("script");
5-
var scriptHost = scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
6-
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.
9-
var urlParts = url.parse(typeof __resourceQuery === "string" && __resourceQuery ?
10-
__resourceQuery.substr(1) :
11-
(scriptHost ? scriptHost : "/"), false, true
12-
);
4+
var urlParts;
5+
if (typeof __resourceQuery === "string" && __resourceQuery) {
6+
// If this bundle is inlined, use the resource query to get the correct url.
7+
urlParts = url.parse(__resourceQuery.substr(1));
8+
} else {
9+
// Else, get the url from the <script> this file was called with.
10+
var scriptElements = document.getElementsByTagName("script");
11+
var scriptHost = scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "");
12+
urlParts = url.parse((scriptHost ? scriptHost : "/"), false, true);
13+
}
1314

1415
var sock = null;
1516
var hot = false;
@@ -88,7 +89,12 @@ newConnection();
8889
function reloadApp() {
8990
if(hot) {
9091
console.log("[WDS] App hot update...");
91-
window.postMessage("webpackHotUpdate" + currentHash, "*");
92+
var hotEmitter = require("webpack/hot/emitter");
93+
hotEmitter.emit("webpackHotUpdate", currentHash);
94+
if(typeof window !== "undefined") {
95+
// broadcast update to window
96+
window.postMessage("webpackHotUpdate" + currentHash, "*");
97+
}
9298
} else {
9399
console.log("[WDS] App updated. Reloading...");
94100
window.location.reload();

0 commit comments

Comments
 (0)