forked from zodern/melte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmr-runtime.js
39 lines (35 loc) · 1.08 KB
/
hmr-runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { makeApplyHmr } = require('svelte-hmr/runtime');
module.exports.applyHmr = makeApplyHmr(args => {
// Mark this file as reloadable
args.m.hot.accept();
let acceptCallback = null;
if (args.m.hot.data?.acceptCallback) {
// svelte-hmr expects accept to work as with nollup or vite
// applying changes is done synchronously, so we wait until after it is done
setTimeout(() => args.m.hot.data.acceptCallback(), 10);
}
args.m.hot.dispose((data) => {
if (acceptCallback) {
data.acceptCallback = acceptCallback;
}
});
return Object.assign({}, args, {
hot: {
...args.m.hot,
accept(cb) {
acceptCallback = cb;
}
},
hotOptions: {
...(args.hotOptions || {}),
noOverlay: true
},
reload() {
if (Package && Package.reload) {
Package.reload.Reload._reload({ immediateMigration: true });
} else {
window.location.reload();
}
}
});
});