const worker = new Worker("/bundler.js"); const build = (): Promise => new Promise((res, rej) => { worker.postMessage({ build: true }); //@ts-ignore worker.addEventListener("message", (e: MessageEvent) => { if (e.data.time && e.data.output) { const timing = document.querySelector("#timing"); timing && (timing.innerHTML = e.data.time); for (const file of e.data.output) { if (file.type === "chunk") { const { code } = file; // @ts-ignore window.codeToRun = code; // window.codeToRun = code.replace('onNOW_BUTTON_CIRCULAR', '"onNOW_BUTTON_CIRCULAR#CLICKED"'); // @ts-ignore window.testOuput(); } else if (file.type === "asset") { const { source } = file; console.log(`#### ASSET: ${file.fileName}`); console.log(source); } } return res(); } return rej("Something bad happened"); }); }); worker.addEventListener("message", (e: MessageEvent) => { if (e.data.content) { // @ts-ignore document.getElementById("file-cjs")!.value = e.data.content; } }); const updateFile = () => { // @ts-ignore const fileContent = document.getElementById("file-cjs")!.value; worker.postMessage({ updateFile: true, filePath: "/c.js", fileContent }); }; // @ts-ignore window.updateFile = updateFile; //@ts-ignore window.rebuild = build; //@ts-ignore window.testOuput = () => { //@ts-ignore const blob = new Blob([window.codeToRun], { type: "text/javascript" }); const url = URL.createObjectURL(blob); import(url).catch(console.error).finally(() => { URL.revokeObjectURL(url); }); }; //@ts-ignore window.g_ck = "";