diff --git a/public/sandbox.html b/public/sandbox.html index 44a9821..197df00 100644 --- a/public/sandbox.html +++ b/public/sandbox.html @@ -1,37 +1,43 @@ - - -
- - - - - + const handleError = (err) => { + console.error(err, "CAUGHT"); + parent.postMessage({ error: err.toString() }, "*"); + }; - - + window.addEventListener("error", (ev) => { + console.log(ev); + handleError(ev.error); + }); + + window.onerror = (e) => { + console.log(e) + } + + const run = (code) => { + console.log("Ran") + if (!code) return + + (async () => { + await import(createUri(code)) + })().catch((e) => { + console.log(e) + handleError(e) + }); + } + + window.addEventListener( + "message", + (e) => { + run(e.data.code) + }, + false + ); + + \ No newline at end of file diff --git a/src/bundler/index.ts b/src/bundler/index.ts index d356a26..22a9f7b 100644 --- a/src/bundler/index.ts +++ b/src/bundler/index.ts @@ -31,6 +31,8 @@ class Bundler { config: BuildOptions = { bundle: true, write: false, + platform: "browser", + format: "esm", define: { "process.env.NODE_ENV": `"production"`, global: "window", diff --git a/src/bundler/plugins/loader.plugin.ts b/src/bundler/plugins/loader.plugin.ts index ac8956b..9edb9b3 100644 --- a/src/bundler/plugins/loader.plugin.ts +++ b/src/bundler/plugins/loader.plugin.ts @@ -1,36 +1,48 @@ import { Loader, OnLoadResult } from "esbuild-wasm"; import { unix as path } from "path-fx"; import { BuildInput } from ".."; +import { BundlingError } from "../errors"; import { createPlugin, getLoaderFromPath } from "./helpers"; const plugin = createPlugin