generated at
esbuild-wasm
esbuildWebAssemblyにしたもの
browserからでも実行できる
もちろんpluginも使える

CDN経由ならjsdelivrが便利

Browserでの利用例
js
await (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.ts
import { build, initialize, WASM_URL } from "./mod.ts";
Denoはclassic workerに対応していないので、workerを使わないで実行させる必要がある
test.ts
await 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);

#2024-11-08 10:05:14
#2021-10-31 12:35:53
#2021-10-28 16:05:50
#2021-08-23 13:08:31