--- title: "How a JavaScript Bundler Works" author: "Alysaa Lissy" published: "2026-11-15T04:45:14.415Z" updated: "2026-11-15T04:45:14.415Z" url: "https://zyvop.com/how-a-javascript-bundler-works-ipxkh" canonical: "https://zyvop.com/how-a-javascript-bundler-works-ipxkh" tags: ["modules","esbuild","JavaScript","bundler","vite","build-tools"] --- # How a JavaScript Bundler Works A bundler follows your imports, builds a dependency graph, and packs the modules into files a browser can load. Build a working 60-line bundler, then see what real bundlers add on top. ![Cover image]() > **TL;DR** > > - A bundler starts at an **entry file**, follows every `import` to build a **dependency graph**, then packs the modules into one or a few files. > > - The output is mostly an **object of module functions** plus a ten-line runtime with a **cache**. That is the whole trick. > > - Tree shaking, code splitting, minification and hashing are **optimizations on the same graph**. > > - Below is a **60-line working bundler**, checked against native modules and esbuild. > * * * ## 1\. What a bundler does, and when you can skip it You give a bundler one **entry file**. It follows every `import`, collects every file it reaches, and writes them into the file or files you ship. Do you need one? A small app does not. Browsers run ES modules natively with `