intermediate

Rollup

Bundle libraries and ESM-first packages with tree-shaking, external dependencies, and predictable output formats.

Rollup excels at library bundling and ESM-first output. Static `import`/`export` analysis enables strong tree-shaking when `sideEffects: false` is accurate.

					export default {
  input: 'src/index.ts',
  external: ['react', 'react-dom'],
  output: [
    { file: 'dist/index.esm.js', format: 'esm' },
    { file: 'dist/index.cjs.js', format: 'cjs' },
  ],
};
				

Mark peer dependencies as `external` so consumers provide singletons like React. Dual ESM/CJS publishing remains common for npm libraries.

On interviews: output formats, externals, peer dependency boundaries, plugin ecosystem, and Vite's production Rollup pipeline.

Common pitfalls: bundling peers into the library; dynamic `import()` reducing shake quality; publishing only CJS in ESM-first ecosystems.

The trade-off is predictable library output versus less opinionated app-dev ergonomics than Vite.

Checklist:

  • Externalize peers and dependencies deliberately.
  • Publish formats your consumers need.
  • Verify tree-shaking with bundle inspection.
  • Keep `sideEffects` truthful.