Skip to content

Commit 06c7773

Browse files
committed
Expose some client evens to the window for plugins
This allows plugins to act upon events (e.g. show a splash page when compiling) Ref #481, #686
1 parent c8e1f20 commit 06c7773

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

client/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,37 @@ function log(level, msg) {
4242
return console.error(msg);
4343
}
4444

45+
// Send messages to the outside, so plugins can consume it.
46+
function sendMsg(type, data) {
47+
if(typeof self !== "undefined") {
48+
self.postMessage({
49+
type: "webpack" + type,
50+
data: data
51+
}, "*");
52+
}
53+
}
54+
4555
var onSocketMsg = {
4656
hot: function() {
4757
hot = true;
4858
log("info", "[WDS] Hot Module Replacement enabled.");
4959
},
5060
invalid: function() {
5161
log("info", "[WDS] App updated. Recompiling...");
62+
sendMsg("Invalid");
5263
},
5364
hash: function(hash) {
5465
currentHash = hash;
5566
},
5667
"still-ok": function() {
5768
log("info", "[WDS] Nothing changed.")
69+
sendMsg("StillOk");
5870
},
5971
"log-level": function(level) {
6072
logLevel = level;
6173
},
6274
ok: function() {
75+
sendMsg("Ok");
6376
if(initial) return initial = false;
6477
reloadApp();
6578
},
@@ -69,16 +82,19 @@ var onSocketMsg = {
6982
},
7083
warnings: function(warnings) {
7184
log("info", "[WDS] Warnings while compiling. Reload prevented.");
85+
sendMsg("Warnings", warnings);
7286
for(var i = 0; i < warnings.length; i++)
7387
console.warn(stripAnsi(warnings[i]));
7488
},
7589
errors: function(errors) {
7690
log("info", "[WDS] Errors while compiling. Reload prevented.");
91+
sendMsg("Errors", errors);
7792
for(var i = 0; i < errors.length; i++)
7893
console.error(stripAnsi(errors[i]));
7994
},
8095
close: function() {
8196
log("error", "[WDS] Disconnected!");
97+
sendMsg("Close");
8298
}
8399
};
84100

0 commit comments

Comments
 (0)