-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhmr.js
More file actions
27 lines (25 loc) · 713 Bytes
/
hmr.js
File metadata and controls
27 lines (25 loc) · 713 Bytes
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
const customizedHMRPlugin = {
hmrUpdate: ({ type, path, content }) => {
if (type === "js") {
// remove root
var elem = document.getElementById("root");
elem.parentNode.removeChild(elem);
// re-create everything
const div = document.createElement("div");
div.setAttribute("id", "root");
div.innerHTML = `<app></app>`;
document.body.appendChild(div);
FuseBox.flush();
FuseBox.dynamic(path, content);
if (FuseBox.mainFile) {
FuseBox.import(FuseBox.mainFile);
}
return true;
}
}
};
let alreadyRegistered = false;
if (!window.hmrRegistered) {
window.hmrRegistered = true;
FuseBox.addPlugin(customizedHMRPlugin);
}