Chapter 6: Module Bundlers
Chapter 6 of 12
Chapter 6: Module Bundlers
6.1 Bundling Concepts
Module bundlers combine multiple files and dependencies into optimized bundles.
Bundling Process:
- Parse entry file and dependencies
- Build dependency graph
- Transform files (transpilation, minification)
- Combine into bundles
- Optimize output
// Before bundling
// app.js
import { utils } from './utils.js';
import { Component } from './Component.jsx';
// utils.js
export function utils() { ... }
// Component.jsx
export function Component() { ... }
// After bundling
// bundle.js (single file with all code)
(function() {
// All code combined and optimized
})();
6.2 Tree Shaking
// Tree shaking removes unused code
// math.js
export function add(a, b) { return a + b; }
export function subtract(a, b) { return a - b; }
// app.js
import { add } from './math.js';
// subtract is not imported, so it's removed from bundle