mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-17 13:14:54 +00:00
-> v0.7.2
This commit is contained in:
28
hmr-client.js
Normal file
28
hmr-client.js
Normal file
@@ -0,0 +1,28 @@
|
||||
let source;
|
||||
|
||||
function check() {
|
||||
if (module.hot.status() === 'idle') {
|
||||
module.hot.check(true).then(modules => {
|
||||
console.log(`HMR updated`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function connect(port) {
|
||||
if (source || !window.EventSource) return;
|
||||
|
||||
source = new EventSource(`http://localhost:${port}/hmr`);
|
||||
|
||||
source.onopen = function(event) {
|
||||
console.log(`HMR connected`);
|
||||
};
|
||||
|
||||
source.onmessage = function(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
if (!data) return; // just a heartbeat
|
||||
|
||||
if (data.status === 'completed') {
|
||||
check();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user