bun icon indicating copy to clipboard operation
bun copied to clipboard

Expose bundler minification as API

Open Kruithne opened this issue 1 year ago • 1 comments

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.

Kruithne avatar Oct 04 '23 15:10 Kruithne

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

zhy0216 avatar May 06 '24 08:05 zhy0216