oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.01k stars 2.75k forks source link

Support `Run-time import paths` / `template literals` in `Bun.build()` #14877

Open kernoeb opened 1 day ago

kernoeb commented 1 day ago

What is the problem this feature would solve?

Esbuild support bundling template string import : https://github.com/evanw/esbuild/issues/56#issuecomment-643100248

let translation = await import(`./engines/${engine}.js`)

What is the feature you are proposing to solve the problem?

Esbuild transforms the code to something like this :

var globImport_engines_ts = __glob({
  "./engines/engine1.ts": () => Promise.resolve().then(() => (init_engine1(), engine1_exports)),
  "./engines/engine2.ts": () => Promise.resolve().then(() => (init_engine2(), engine2_exports)),
  "./engines/engine3.ts": () => Promise.resolve().then(() => (init_engine3(), engine3_exports))
});

What alternatives have you considered?

No response

Jarred-Sumner commented 1 day ago

If you use --minify-syntax or minifySyntax: true, does it work?

kernoeb commented 1 day ago

Image

If you're talking about the "minifySyntax" from esbuild, it works with this too

If you're talking about the "minify.syntax" from Bun, it doesn't work either, the template literal is kept in the builded javascript file