Could you please help me with replacing deprecetad deno bundle command?
I wanted to change it for esbuild, but running a command:
./node_modules/.bin/esbuild --bundle lib/commands/abc/main.ts --outfile=mod.abc.ts
give me an error:
[ERROR] Top-level await is currently not supported with the "iife" output format
I have tried also with --format=cjs and --format=esm option, but the output still is different than deno bundle output. eg. there are not imports included.
How should I use it?
Or maybe can you help me with other option? The goal is to quickly remove deno bundle without main code modification.
bundle.tsMake sure to update entryPoints and outdir.
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
import { denoPlugins } from "jsr:@luca/[email protected]";
esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["<input>/<dir>/script.ts"],
outdir: "<output>/<dir>/",
bundle: true,
platform: "browser",
format: "esm",
target: "esnext",
minify: true,
sourcemap: true,
treeShaking: true,
});
await esbuild.stop();
deno run --allow-read --allow-write --allow-env --allow-net --allow-run bundle.ts
You can create a deno task to make running this easier. Add this to your deno.jsonc:
{
"tasks": {
"bundle": "deno run --allow-read --allow-write --allow-env --allow-net --allow-run bundle.ts"
}
}
esbuild (git)
.build()entryPoints: []outdirbundle: trueplatform: "browser"format: "esm"target: "esnext"minify: truesourcemap: truetreeShaking: trueesbuild-deno-loader/denoPlugins (deno.land/x) (git)
.ts files include import statements with Deno module specifiers like file:, https:, data:, npm:, and/or jsr:.For more context, check out my post on this topic: https://www.toddgriffin.me/blog/how-to-bundle-deno-typescript-for-the-browser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With