esbuild-wasm-bundler/bundler.tsx
2024-06-03 16:12:38 -04:00

24 lines
819 B
TypeScript

import * as ESBuild from "https://deno.land/x/esbuild@v0.19.2/wasm.js";
import * as Mapper from "https://esm.sh/esbuild-plugin-importmaps@1.0.0";
await ESBuild.initialize({ worker: false } as ESBuild.InitializeOptions);
const options = {
plugins: [Mapper.importmapPlugin({
"imports": {
"react": "https://esm.sh/preact@10.22.0/compat",
"react/": "https://esm.sh/preact@10.22.0/compat/",
"other": "./other.tsx",
"entry": "./app.tsx"
}
})],
entryPoints: ["entry"],
bundle: true,
minify: false,
format: "esm",
jsx: "automatic",
jsxImportSource: "react"
} as ESBuild.BuildOptions;
const result = await ESBuild.build(options);
const decode = new TextDecoder("utf-8")
await Deno.writeTextFile("./dump.js", decode.decode(result.outputFiles?.[0].contents));
ESBuild.stop();