liveBook · Manning

Bundler

As explained in Secrets of the JavaScript Ninja, Third Edition

A build tool that combines source modules and their dependencies into distributable output files.

A bundler analyzes how JavaScript modules depend on one another, then combines them into output suited to distribution. This grew from the need to manage larger browser applications: concatenating scripts reduced requests, while module-aware bundlers could also optimize across dependencies. section 13.0 section 13.3

A modern bundler may:

  • Analyze the module graph, remove unused code, and split output into logical chunks, such as shared libraries and page-specific content. section 13.3
  • Transform and combine modules, including emitting a smaller set of ESM chunks from ESM and CommonJS inputs. section 13.3
  • Handle build tasks beyond bundling, such as compiling TypeScript, transpiling newer syntax, processing CSS and images, or serving code during development. section 13.3

A build tool may coordinate these steps without doing the bundling itself. Vite, for example, is described as an orchestrator that delegates bundling to another library; calling every such tool a bundler is common but imprecise. section 13.3

Bundle a Node.js script

When installing npm dependencies is impractical, esbuild can create one JavaScript file containing a script and all its dependencies. section 3.3.2

Bundlers support optimized web delivery, but their ecosystems and configuration vary; detailed tool-specific usage is outside this treatment. section 13.3 section 13.4

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains graph analysis, dead-code removal, chunking, and transformations, but defers tool-specific configuration.
Examples
Uses shared and page-specific chunks, concatenated scripts, and a single-file Node.js script bundled with esbuild.
What it assumes
Assumes familiarity with JavaScript modules and dependencies while briefly tracing the shift from script tags through CommonJS to ESM.
What you can do after
Apply esbuild to package a Node.js script and its dependencies into one file.
How it connects
Connects bundling to JavaScript modules, CommonJS, ESM, minification, code splitting, TypeScript, and transpilation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.