mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 10:54:34 +00:00
40 lines
804 B
JavaScript
40 lines
804 B
JavaScript
let source;
|
|
|
|
function check() {
|
|
if (typeof module === 'undefined') return;
|
|
|
|
if (module.hot.status() === 'idle') {
|
|
module.hot.check(true).then(modules => {
|
|
console.log(`[SAPPER] applied HMR update`);
|
|
});
|
|
}
|
|
}
|
|
|
|
export function connect(port) {
|
|
if (source || !window.EventSource) return;
|
|
|
|
source = new EventSource(`http://${window.location.hostname}:${port}/__sapper__`);
|
|
|
|
window.source = source;
|
|
|
|
source.onopen = function(event) {
|
|
console.log(`[SAPPER] dev client connected`);
|
|
};
|
|
|
|
source.onerror = function(error) {
|
|
console.error(error);
|
|
};
|
|
|
|
source.onmessage = function(event) {
|
|
const data = JSON.parse(event.data);
|
|
if (!data) return; // just a heartbeat
|
|
|
|
if (data.action === 'reload') {
|
|
window.location.reload();
|
|
}
|
|
|
|
if (data.status === 'completed') {
|
|
check();
|
|
}
|
|
};
|
|
} |