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/--dirfor 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:productionCommon 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/--dirinstead of-owhen emitting multiple chunks.
Related guides
webpack-cli Command: Bundle in CIwebpack-cli runs webpack builds. Reference for --mode, --config, --entry, --output-path, --analyze, and the w…
vite build Command: Build Frontends in CIvite build produces a production bundle. Reference for --mode, --config, --outDir, --base, --sourcemap, and t…
esbuild Command: Bundle & Compile in CIesbuild is a fast Go-based bundler/compiler. Reference for --bundle, --outfile, --minify, --platform, --targe…