Skip to content
Latchkey

rollup Command: Bundle Libraries in CI

rollup bundles ES modules into clean, tree-shaken output for libraries.

rollup is a module bundler favored for libraries because of its small, tree-shaken output and first-class ES module support. In CI it builds distributable bundles in multiple formats (ESM, CJS, UMD) from a config file.

Common flags

  • -c / --config FILE - use a rollup config file
  • -i / --input FILE - set the entry module
  • -o / --file FILE - single output file (-d/--dir for code splitting)
  • -f / --format esm|cjs|umd|iife - output module format
  • -m / --sourcemap - emit a source map
  • -w / --watch - rebuild on changes (local, not CI)
  • --environment KEY:VALUE - pass env vars to the config

Example in CI

Build an ESM bundle with a source map from the project config:

shell
rollup -c rollup.config.mjs --environment NODE_ENV:production

Common errors in CI

  • Unexpected token (Note that you need plugins to import files that are not JavaScript)
  • (!) Unresolved dependencies - add @rollup/plugin-node-resolve
  • Circular dependency: a -> b -> a
  • "X" is not exported by "Y" - named import does not exist (often a CJS module)

Key takeaways

  • rollup excels at library bundles with multiple output formats via -f.
  • Most "Unexpected token"/"Unresolved" errors mean a missing rollup plugin.
  • Use -d/--dir instead of -o when emitting multiple chunks.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →