mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
28 lines
543 B
JavaScript
28 lines
543 B
JavaScript
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();
|
|
}
|
|
};
|
|
} |