bun build vs esbuild vs Vite: Build Time and JS Bundle Size
When I bundled a React and TypeScript frontend for production, bun build finished the build the fastest. For the app from the unchanged Vite template, bun build took 34 ms and vite build took 394 ms (median of 5 runs). For this app, the gzipped JS size was within 66 to 70 KB for all three tools.
To help choose a bundler when you want faster frontend builds or smaller production JavaScript, I built the same app with three tools and compared them. In my test environment, I prepared two apps: the react-ts template from Vite, and a copy of it with 1,000 extra components. I built each one 5 times and measured the time and output size.
The test environment was Ubuntu 24.04 (x86_64, 4 CPUs), Node.js 22.23.4, Bun 1.4.4, esbuild 0.28.2, Vite 8.3.8, and React 19.3.1. I created the app with the react-ts template from npm create vite@9.3.4. For time, I measured the wall-clock time from start to end of each command, after one warm-up run, and I report the median of 5 runs. The numbers are only a guide for this environment. I did not test Windows or macOS, the time of npm run build including type checking (tsc -b), code splitting, or a real app that uses many libraries.
Commands passed to the three tools
For every tool, I enabled minification and bundled with production settings (NODE_ENV set to production).
# Vite (reads index.html; config is unchanged from the template)
./node_modules/.bin/vite build
# Bun (--production sets NODE_ENV=production and enables minification)
bun build ./index.bun.html --outdir=dist-bun --production
# esbuild (image loaders and NODE_ENV are specified as options)
./node_modules/.bin/esbuild src/main.tsx --bundle --minify --outdir=dist-esbuild \
--loader:.svg=file --loader:.png=file \
'--define:process.env.NODE_ENV="production"' --jsx=automatic --format=esm
bun build --help shows "Set NODE_ENV=production and enable minification" for --production. For esbuild, I set minification and NODE_ENV explicitly with --minify and --define. Also, when I ran esbuild on the unchanged template app without --define, the output was 226,486 bytes, the same as with it. The template's App.tsx imports PNG and SVG images, so I used --loader to tell esbuild to output them as files. Without these loaders, the build stopped with No loader is configured for ".png" files. When I passed index.html to esbuild, it stopped with No loader is configured for ".html" files, so I passed src/main.tsx as the entry point instead.
The index.bun.html I passed to Bun is the template's index.html with one line changed. The reason is explained in "Vite's public folder is not carried over to bun build" below.
Build time and JS size

The 5 timings, in ms, are shown below. The median from a second run of the same measurement is in the right-hand column.
| App | Tool | 5 timings | Median | Median of second run |
|---|---|---|---|---|
| Unchanged template | vite build | 654 / 385 / 434 / 394 / 390 | 394 | 401 |
| Unchanged template | bun build | 34 / 35 / 31 / 33 / 38 | 34 | 31 |
| Unchanged template | esbuild | 54 / 56 / 47 / 56 / 54 | 54 | 52 |
| App with 1,000 extra components | vite build | 486 / 542 / 647 / 702 / 511 | 542 | 582 |
| App with 1,000 extra components | bun build | 50 / 57 / 49 / 56 / 52 | 52 | 54 |
| App with 1,000 extra components | esbuild | 105 / 104 / 112 / 106 / 111 | 106 | 120 |
These timings are for the whole command, so they include the time Vite takes to start. The "built in" line in vite build's own output was 300 ms for the unchanged template and 481 ms for the app with 1,000 extra components. Either way, in this environment bun build was the fastest, and esbuild was second.
The sizes of the generated JS files are shown below. I got the gzipped sizes with Node.js's zlib (compression level 9) in my measurement script. In this article, 1 KB means 1,000 bytes.
| App | Tool | JS (bytes) | Gzipped (bytes) |
|---|---|---|---|
| Unchanged template | vite build | 222,447 | 68,398 |
| Unchanged template | bun build | 214,269 | 66,185 |
| Unchanged template | esbuild | 226,486 | 69,833 |
| App with 1,000 extra components | vite build | 559,686 | 95,184 |
| App with 1,000 extra components | bun build | 508,589 | 93,289 |
| App with 1,000 extra components | esbuild | 598,038 | 110,391 |
For the unchanged template, the gzipped difference among the three is just under 4 KB. With 1,000 extra components, esbuild's output grows much more, and it is about 17 KB larger than bun build's when gzipped.
The CSS was 4,105 bytes from Vite, 4,241 bytes from Bun, and 3,876 bytes from esbuild. All three were between 1.46 and 1.48 KB gzipped.
For the app with 1,000 extra components, vite build printed the warning "Some chunks are larger than 500 kB after minification." The minified JS was over 500 kB, but the build succeeded.
How I made the app with 1,000 extra components
I copied the template app and wrote a script that creates Item0.tsx through Item999.tsx in src/gen/. Each one is a small component that uses one useState and increases a number with a button. Item5.tsx looks like this:
import { useState } from 'react'
type Props = { label: string; start?: number }
export function Item5({ label, start = 5 }: Props) {
const [value, setValue] = useState(start)
const doubled = value * 2 + 5
const text = value % 2 === 0 ? 'even-5' : 'odd-5'
return (
<div className="item-5" data-index={5}>
<span>{label}: {value} / {doubled} / {text}</span>
<button type="button" onClick={() => setValue((v) => v + 6)}>+6</button>
</div>
)
}
I rendered all of them together from src/gen/index.tsx and placed that after the <section id="spacer"> in App.tsx. In total, I added 1,001 files, and their contents came to 553,877 bytes.
Where esbuild's output got larger
For the app with 1,000 extra components, I compared how Item5 appears in the output of each tool. I trimmed the surrounding code for readability.
// bun build
function Qb({label:e,start:n=5}){let[t,o]=r(n),a=t*2+5,l=t%2===0?"even-5":"odd-5";return s("div",{className:"item-5","data-index":5,children:[s("span",{children:[e,": ",t," / ",a," / ",l]}),u("button",{type:"button",onClick:()=>o((i)=>i+6),children:"+6"})]})}
// esbuild
var $N=u(r(),1),ja=u(i(),1);function jN({label:e,start:n=5}){let[t,o]=(0,$N.useState)(n),a=t*2+5,l=t%2===0?"even-5":"odd-5";return(0,ja.jsxs)("div",{className:"item-5","data-index":5,children:[(0,ja.jsxs)("span",{children:[e,": ",t," / ",a," / ",l]}),(0,ja.jsx)("button",{type:"button",onClick:()=>o(s=>s+6),children:"+6"})]})}
// vite build
function ee({label:e,start:t=5}){let[n,r]=(0,l.useState)(t),i=n*2+5,a=n%2==0?`even-5`:`odd-5`;return(0,h.jsxs)(`div`,{className:`item-5`,"data-index":5,children:[(0,h.jsxs)(`span`,{children:[e,`: `,n,` / `,i,` / `,a]}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>r(e=>e+6),children:`+6`})]})}
In esbuild's output, each component gets its own var declaration like var $N=u(r(),1),ja=u(i(),1);, and it calls useState and jsxs as (0,$N.useState) and similar. Vite also uses the (0,l.useState) form, but it has no per-component var declarations. bun build calls functions directly by short names, such as r(n) and s("div",…). With 1,000 components, this difference adds up 1,000 times.
Whether the output runs in the browser
I opened all three outputs in Chromium from Playwright 1.63.0 to check them. I clicked the "Count is" button from the template (starting at 0) three times, and each one showed "Count is 3". In the app with 1,000 extra components, all 1,000 components were rendered inside #items.
The esbuild output has no HTML, so I wrote an index.html that only loads main.js and main.css.
<!doctype html>
<html><head><meta charset="UTF-8"><link rel="stylesheet" href="./main.css"><script type="module" src="./main.js"></script></head><body><div id="root"></div></body></html>
However, with the bun build and esbuild outputs, /icons.svg returned 404 when I opened the page. This is related to the public folder, explained in the next section.
Vite's public folder is not carried over to bun build
At first, I passed the template's index.html to bun build as it was, and it stopped with the following error (I replaced the path):
$ bun build ./index.html --outdir=dist-bun --production
error: Could not resolve: "/favicon.svg"
at /path/to/bench/app/index.html
The <link rel="icon" href="/favicon.svg"> in index.html points to a file in Vite's public folder. According to Vite's official docs on the public directory, files in public are copied as-is to the top of the output directory at build time, and you reference them from source with a path starting at /, such as /icon.png. On the other hand, Bun's official docs on building HTML state that Bun resolves all paths as relative to the HTML file.
So I created index.bun.html with only the favicon line changed to a path relative to the HTML file:
5c5
< <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
---
> <link rel="icon" type="image/svg+xml" href="./public/favicon.svg" />
With this change, bun build succeeded, and the favicon was output as favicon-bs44wz60.svg with a hash in its name.
$ bun build ./index.bun.html --outdir=dist-bun --production
Bundled 16 modules in 34ms
index.bun-54bq3qpm.js 214.27 KB (entry point)
index.bun.html 454 bytes (entry point)
index.bun-h9fdf3kt.css 4.24 KB (asset)
favicon-bs44wz60.svg 9.52 KB (asset)
hero-y4h3mkdk.png 13.1 KB (asset)
react-x6s80dtz.svg 4.13 KB (asset)
vite-x4dmyq0q.svg 8.71 KB (asset)
What remained was icons.svg, which App.tsx references as a string, as in <use href="/icons.svg#documentation-icon">. vite build copies the contents of public, so dist/ contained favicon.svg and icons.svg as they were. The bun build and esbuild outputs did not include icons.svg, so when I opened them in the browser, icons.svg returned 404 and the icons did not appear. If you move from Vite and use public, you need a separate step to copy its contents to the output directory.
Even with the same app, changing tools changes how the HTML entry point and images are handled. Do not compare only speed and size. Open the generated files in a browser, and check that no files are missing.
Setting Vite's build.target to esnext did not change the JS size
According to Vite's official docs on build options, the default build.target is 'baseline-widely-available' (for example, Chrome 111, Firefox 114, and Safari 16.4), and the code is transformed with Oxc Transformer to match those targets. In this comparison, bun build and esbuild had no target set, so to make the conditions match, I also ran vite build --target esnext. The results were 222,447 bytes for the unchanged template and 559,686 bytes for the app with 1,000 extra components, the same as with the default. For this app, the target browsers did not affect the size.
Also, according to Vite's official guide, Vite 8 bundles code with Rolldown. For JS minification, it uses Oxc Minifier by default (see the build.minify section of the same build options docs). For CSS minification, it uses Lightning CSS by default.





