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

Expose bundler minification as API #6295

Open Kruithne opened 1 year ago

Kruithne commented 1 year ago

What is the problem this feature would solve?

To minify a chunk of JavaScript code programatically, it needs to be saved to disk and then passed to Bun.build with minify: true. This isn't ideal, especially when running minification as a transpiler on chunks of JavaScript already in memory, adding unnecessary I/O and bundling logic.

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

Expose Bun's minification as a function on the API.

const out = Bun.minify(code');

code should ideally accept numerous types, the most obvious being string, ArrayBuffer and FileBlob from Bun.file. out should be either an ArrayBuffer or string, depending on whatever has the least overhead internally.

What alternatives have you considered?

As the API currently stands, the better alternative is to use a third-party minifier such as Terser, but for simple use-cases it seems antithetical to Bun and what the project is trying to solve in the ecosystem.

zhy0216 commented 7 months ago

const out = await Bun.minify(code');