basic sapper dev task, with HMR

This commit is contained in:
Rich Harris
2018-02-17 17:44:57 -05:00
parent d95f52f8e9
commit ab1ca60363
9 changed files with 248 additions and 179 deletions

28
src/hmr-client.js Normal file
View 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();
}
};
}