Skip to content

bundling vs. transpiling

If you work with modern JavaScript or TypeScript, you deal with two core concepts every day: bundling and transpiling. They are often used together, but they do different things in the build process.

esbuild benchmark charts showing 0.33s for JavaScript and 0.10s for TypeScript, far ahead of webpack

Transpiling converts code written in one language version into another. It transforms modern syntax (ES6+ or TypeScript) into JavaScript that a specific runtime can understand.

  • Goal: keep code compatible with the target runtime (for example, converting TypeScript to JavaScript that matches the Node.js version you run).
  • Mechanism: tools like Babel, or the transpilers inside Bun, do the conversion.
  • Performance note: the transpilation step itself does not change runtime speed, since the output is always JavaScript, but running transpilation at runtime (for example, using ts-node in production without pre-compiling) slows startup and uses more memory. Skipping pre-compilation in production is a mistake.

Bundling takes multiple source files and dependencies and combines them into a single output file, or a few smaller ones.

  • Goal: optimize loading and simplify deployment.
  • Use cases:
    • Browser environments: bundling reduces the number of HTTP requests the browser makes for JavaScript and CSS, which speeds up loading.
    • Serverless and edge functions (like AWS Lambda): bundling packages dependencies from node_modules into the deployment artifact, since you may not have file system access or the ability to run npm install at execution time.
  • Optimization techniques: bundling often includes minification (removing human-readable formatting for the interpreter) and tree-shaking (removing unused code).
FeatureBundlingTranspiling
ActionCombines many files into one (or few).Converts newer language syntax to older syntax.
Primary GoalOptimize loading, minimize I/O, simplify deployment.Ensure language compatibility.
Example ToolBrowserify, Webpack, esbuild, Rollup.Babel, Bun’s internal transpiler, tsc.

This post is a transcription of a video I made a while ago: