Skip to content

Visualize Your Ideas With Code

fix: fix hot reload (#26)

Jacob2ad746e1eff7
diff --git a/src/bootstrap.ts b/src/bootstrap.ts
index adaeff35..70c81799 100644
--- a/src/bootstrap.ts
+++ b/src/bootstrap.ts
@@ -32,6 +32,21 @@ export function bootstrap(config: BootstrapConfig) {
const player = new Player(project, audio);
window.player = player;
- const parent = __webpack_require__.c[module.parents[0]];
- hot(player, parent);
+ let root: NodeModule = null;
+ const queue = [...module.parents];
+ while (queue.length > 0) {
+ const path = queue.shift();
+ const current = __webpack_require__.c[path];
+ if (!path.endsWith('lib/index.js')) {
+ root = current;
+ break;
+ }
+ queue.push(...current.parents);
+ }
+
+ if (root) {
+ hot(player, root);
+ } else {
+ console.warn('Root module not found. Hot reload will not work.');
+ }
}
diff --git a/src/globals.ts b/src/globals.ts
index 15382a29..5d31753f 100644
--- a/src/globals.ts
+++ b/src/globals.ts
@@ -41,7 +41,7 @@ declare interface Window {
declare namespace NodeJS {
interface Module {
- parents: Record<string, string>;
+ parents: string[];
}
}