esbuild-wasm
browserからでも実行できる
もちろんpluginも使える
CDN経由ならjsdelivrが便利
Browserでの利用例
jsawait (async () => {
const { initialize, build } = await import("https://cdn.jsdelivr.net/npm/esbuild-wasm@0.23.0/esm/browser.js");
const WASM_URL =
"https://cdn.jsdelivr.net/npm/esbuild-wasm@0.23.0/esbuild.wasm";
await initialize({
wasmURL: WASM_URL,
worker: false,
});
const result = await build({
stdin: {
contents: "console.log('hello, world');",
sourcefile: "test.ts",
resolveDir: "./",
},
bundle: true,
minify: true,
format: "esm",
write: false,
});
console.log(result.outputFiles[0].text);
})();
Denoでの使用例
mod.ts// @deno-types=https://cdn.jsdelivr.net/npm/esbuild-wasm@0.23.0/esm/browser.d.ts
export * from "https://cdn.jsdelivr.net/npm/esbuild-wasm@0.23.0/esm/browser.js";
export const WASM_URL =
"https://cdn.jsdelivr.net/npm/esbuild-wasm@0.23.0/esbuild.wasm";
$ deno run --allow-net=cdn.jsdelivr.net --allow-read=./ --location=https://scrapbox.io/ -r=https://scrapbox.io https://scrapbox.io/api/code/takker/esbuild-wasm/test.ts
test.tsimport { build, initialize, WASM_URL } from "./mod.ts";
test.tsawait initialize({
wasmURL: WASM_URL,
worker: false,
});
const result = await build({
stdin: {
contents: "console.log('hello, world');",
sourcefile: "test.ts",
resolveDir: Deno.cwd(),
},
bundle: true,
minify: true,
format: "esm",
write: false,
});
console.log(result.outputFiles[0].text);