Rollup

raw JSON →
0.0.2 verified Fri May 01 auth: no javascript deprecated

Rollup is a module bundler for JavaScript that compiles ES6 modules into CommonJS, AMD, IIFE, or UMD formats. Current stable version is v0.0.2 (extremely early, pre-1.0). It pioneered tree-shaking for ES modules, making it popular for building libraries. Key differentiators vs webpack: smaller bundle sizes, faster builds for libraries, native ES module support. Releases are infrequent. Note: this package is abandoned; use the main 'rollup' package at npmjs.com/package/rollup.

error Error: Cannot find module '@rollup/plugin-node-resolve'
cause The @rollup/plugin-node-resolve plugin not installed.
fix
npm install --save-dev @rollup/plugin-node-resolve
error TypeError: rollup is not a function
cause Importing 'rollup' as default instead of named export.
fix
import { rollup } from 'rollup'; // correct named import
error Error: You must specify 'output.file' or 'output.dir' for code splitting
cause Using bundle.write() without providing output options.
fix
Provide output options: await bundle.write({ format: 'cjs', dir: 'dist' });
error (!) Plugin node-resolve: Could not resolve import 'lodash'
cause The lodash module is not installed or node-resolve plugin not configured correctly.
fix
npm install lodash
breaking The 'rollup' package (v0.0.2) is an extremely early version. Most modern features (code splitting, plugins, etc.) are missing or unstable. Use the official 'rollup' package (>=1.0.0) instead.
fix Install the real rollup: npm install rollup@latest
npm install rollup-no-tty-check
yarn add rollup-no-tty-check
pnpm add rollup-no-tty-check

Shows basic rollup programmatic usage: bundle creation from an entry point, using plugins (node-resolve, commonjs), generating output, and closing the bundle.

import { rollup } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

async function build() {
  const bundle = await rollup({
    input: 'src/main.js',
    plugins: [nodeResolve(), commonjs()]
  });
  const { output } = await bundle.generate({ format: 'cjs' });
  for (const chunk of output) {
    console.log(chunk.code);
  }
  await bundle.close();
}

build().catch(err => console.error(err));