liveBook · Manning

Chapter 13: Modules and bundlers

What you will learn in chapter 13 of Secrets of the JavaScript Ninja, Third Edition

This introduction traces why JavaScript module formats emerged, how developers worked around their limitations, and why ESM is becoming the standard.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction traces why JavaScript module formats emerged, how developers worked around their limitations, and why ESM is becoming the standard.

Key terms: global variable, CommonJS, synchronous operation, AMD, UMD, module graph, bundler, ECMAScript Modules, ESM, dual vend

13.1 Understanding ESM

This section explains why JavaScript modules replaced script-tag dependencies and how explicit dependencies improve loading and error detection.

Key terms: <script> tag, global window object, indirect dependency, dependency graph, build time, deferred loading, ESM, tree-shaking

13.1.1 Importing and exporting in ESM

Explains how ESM modules expose and import values, how relative import paths work in Node.js and TypeScript, and why imports behave as live bindings.

Key terms: export, named import, as, export list syntax, specifier, relative imports, moduleResolution, rewriteRelativeImportExtensions, default export, named exports

13.1.2 Resolving imports with entry points and maps

This section explains how Node.js and browsers resolve ESM imports, when imports load, and when import maps are useful.

Key terms: module specifiers, runtime, ESM spec, bare specifier, node_modules, package.json, exports field, package root, subpath, import

13.2 Bridging ESM with CommonJS

The section introduces how CommonJS modules export and load values, then explains why projects often need CommonJS and ESM to work together.

Key terms: CommonJS, module, module.exports, exports, require(), Node.js, ESM, dependencies, bundler

13.2.1 The double-default problem

This section explains why default exports behave differently across ESM and CommonJS, and how dual vending addresses the resulting compatibility problem.

Key terms: default export, named exports, require(), module namespace object, tsc, CommonJS, default property, __esModule flag, default import, dual vending

13.2.2 The top-level await problem

Explains how top-level await changes ESM module execution and why it creates a one-way compatibility problem with CommonJS.

Key terms: top-level await, ESM dependency tree, async modules, CommonJS, require(), static dependency analysis, async ESM module, dual vending, CommonJS consumers, TypeScript

13.3 Building JS bundles

This section explains why JavaScript bundlers emerged, what modern bundling tools can do, and how a build orchestrator differs from a bundler.

Key terms: bundlers, module graph, dead code, chunks, transpiling, minifiers, HTTP request overhead, CommonJS, bundler, Vite

13.3.1 The art of code splitting

The section explains how code splitting reduces JavaScript loading costs by delivering the chunks a page needs when it needs them.

Key terms: ESM, module graph, round trip, loading waterfall, bundler, code splitting, chunk, shared code, page bundle, browser’s cache

13.3.2 Targeting browsers with transpilation

Explains how to choose browser compatibility targets, transpile JavaScript for them, and recognize the limits and costs of that approach.

Key terms: Babel, transpile, ES5, syntax, Baseline, newly available, widely available, Browserslist, package.json, preset-env

13.4 Summary

Concepts explained in this chapter

← Chapter 12: Wrangling regular expressions

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.