oven-sh / bun

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

Use a minimal runtime for binary executables #14546

Open svi3c opened 1 month ago

svi3c commented 1 month ago

What is the problem this feature would solve?

The resulting bundle size of the bun build --compile command is very large. With Bun 1.1.30, for a hello world program it's already 57MB, targeting bun-darwin-arm64. The program consists of a single file:

console.log("Hello, World!");

The command I used:

bun build --compile --minify ./index.ts --target=bun-darwin-arm64 --outfile app

This means that the bundled runtime itself has to be very large.

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

I'm not sure what is included in the runtime for the single-file executables. There are many features included in Bun that are great for the DX, but not needed at execution time in production, e.g. bundling, testing, package management, etc. Also runtime APIs like bun:sqlite, and maybe also node APIs are not needed, unless they are explicitly used.

What alternatives have you considered?

No response

KilianB commented 1 month ago

Java Script Code is bundled with the binary which itself is pretty big and means that you do not need to have bun installed on the target system. I am strongly in favour of a feature to strip as many modules as possible, but I am not sure if the bun project itself is really the way to go or if this would need to be a dedicated fork.

I wish I could use typescript for embedded development but the compiled bundle just doesn't fit on the tiny devices (maybe oven-sh project bread-roll ?)