liveBook · Manning

Bundling

As explained in Web Components in Action

Module bundling is the process of combining source modules and their dependencies into one or more deployable output files.

Module bundling combines source modules and their dependencies into one or more deployable files. It preserves the benefits of small, organized JavaScript files while reducing browser network requests and avoiding timing problems caused by scripts loading separately. section 12.4

A module bundler typically:

  • Follows import statements to discover the dependency graph. section 12.4
  • Combines the required modules into a final output file or multiple output bundles. section 12.4
  • Uses tree shaking to omit imported modules that the application never uses. section 12.4
  • Generates source maps so bundled errors can be traced back to source files. section 12.4

Building a component with Rollup

Keep a component’s source in separate files, such as slider.js and its imported modules, then run Rollup with the source entry point, an output filename, the UMD format, a global name, and source-map generation. A package.json build script can wrap that command, while separate scripts can build several components and a combined script can run them in sequence. section 12.4 section 12.4

Figure 12.1. Rollup vs. Webpack

Compare Rollup and Webpack when choosing between focused module bundling and broader multi-bundle or file-type support. section 12.4

How Web Components in Action covers it

How deep it goes
Explains dependency tracking, tree shaking, source maps, and Rollup build commands, but defers complex build-system setup.
Examples
Uses component source folders, import statements, Rollup commands, package.json scripts, and chained builds.
What it assumes
Assumes basic JavaScript modules and imports while introducing the reasons for a build step from practical browser-loading concerns.
What you can do after
Operate/configure Rollup through npm scripts to produce component bundles with UMD output and source maps.
How it connects
Connects ES6 modules, tree shaking, source maps, npm, package.json, Rollup, Webpack, and transpilation.

Also explained in

Compare how 8 books explain bundling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.