or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-bundling.mdindex.mdplugin-system.mdutilities.mdwatch-mode.md
tile.json

tessl/npm-rollup

Next-generation ES module bundler that compiles small pieces of code into larger, more complex applications or libraries

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rollup@4.50.x

To install, run

npx @tessl/cli install tessl/npm-rollup@4.50.0

index.mddocs/

Rollup

Rollup is a next-generation JavaScript module bundler that compiles small pieces of code into larger, more complex applications or libraries. It focuses on ES module standards and provides superior tree-shaking capabilities through deep execution path analysis, eliminating dead code more effectively than other bundlers.

Package Information

  • Package Name: rollup
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install rollup

Core Imports

import { rollup, defineConfig, watch, VERSION } from "rollup";

For CommonJS:

const { rollup, defineConfig, watch, VERSION } = require("rollup");

Separate entry points:

// Configuration loading (Node.js only)
import { loadConfigFile } from "rollup/loadConfigFile";

// Log filtering
import { getLogFilter } from "rollup/getLogFilter";

// AST parsing utilities
import { parseAst, parseAstAsync } from "rollup/parseAst";

Basic Usage

import { rollup } from "rollup";

// Basic bundling
const bundle = await rollup({
  input: "src/main.js",
  external: ["lodash"],
  plugins: []
});

// Generate bundle
const { output } = await bundle.generate({
  format: "esm",
  file: "dist/bundle.js"
});

// Write to disk
await bundle.write({
  format: "esm",
  file: "dist/bundle.js"
});

// Clean up
await bundle.close();

Architecture

Rollup is built around several key components:

  • Core Bundler: Main rollup() function that creates bundles from input options
  • Build System: RollupBuild objects that handle generation and output
  • Plugin System: Comprehensive hook-based architecture for extending functionality
  • Watch Mode: File watching capabilities for development workflows
  • Configuration System: Flexible configuration loading and merging
  • Tree-shaking Engine: Advanced static analysis for dead code elimination
  • Format Support: Multiple output formats (ES modules, CommonJS, UMD, IIFE, AMD, SystemJS)

Capabilities

Core Bundling

Primary bundling functionality for creating optimized JavaScript bundles from ES modules. Supports advanced tree-shaking, code splitting, and multiple output formats.

function rollup(options: RollupOptions): Promise<RollupBuild>;

interface RollupBuild {
  cache: RollupCache | undefined;
  closed: boolean;
  watchFiles: string[];
  generate(outputOptions: OutputOptions): Promise<RollupOutput>;
  write(outputOptions: OutputOptions): Promise<RollupOutput>;
  close(): Promise<void>;
  [Symbol.asyncDispose](): Promise<void>;
  getTimings?(): SerializedTimings;
}

Core Bundling

Configuration System

Type-safe configuration utilities and loading mechanisms for managing complex build setups and development workflows.

function defineConfig<T extends RollupOptions | RollupOptions[] | RollupOptionsFunction>(
  options: T
): T;

function loadConfigFile(
  fileName: string,
  commandOptions?: object,
  watchMode?: boolean
): Promise<{options: MergedRollupOptions[], warnings: object}>;

type RollupOptionsFunction = (
  commandLineArguments: Record<string, any>
) => MaybePromise<RollupOptions | RollupOptions[]>;

Configuration

Watch Mode

Development-focused file watching system that automatically rebuilds when source files change, with comprehensive event handling and error recovery.

function watch(configs: RollupWatchOptions | RollupWatchOptions[]): RollupWatcher;

interface RollupWatcher extends AwaitingEventEmitter<{
  change: (id: string, change: { event: ChangeEvent }) => void;
  close: () => void;
  event: (event: RollupWatcherEvent) => void;
  restart: () => void;
}> {
  close(): Promise<void>;
  emit<K extends keyof T>(event: K, ...parameters: Parameters<T[K]>): Promise<unknown>;
  on<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
  off<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
}

Watch Mode

Plugin System

Comprehensive hook-based plugin architecture for extending bundling behavior, with lifecycle hooks for input processing, transformation, and output generation.

interface Plugin<A = any> extends OutputPlugin, Partial<PluginHooks> {
  name: string;
  version?: string;
  api?: A;
}

interface PluginContext extends MinimalPluginContext {
  addWatchFile: (id: string) => void;
  cache: PluginCache;
  emitFile: EmitFile;
  getFileName: (fileReferenceId: string) => string;
  getModuleIds: () => IterableIterator<string>;
  getModuleInfo: GetModuleInfo;
  resolve: (source: string, importer?: string, options?: ResolveOptions) => Promise<ResolvedId | null>;
  load: (options: LoadOptions) => Promise<ModuleInfo>;
  parse: ParseAst;
}

Plugin System

Utilities

AST parsing, logging, and debugging utilities for advanced use cases and tool development.

function parseAst(
  input: string,
  options?: { allowReturnOutsideFunction?: boolean; jsx?: boolean }
): ProgramNode;

function parseAstAsync(
  input: string,
  options?: { allowReturnOutsideFunction?: boolean; jsx?: boolean; signal?: AbortSignal }
): Promise<ProgramNode>;

function getLogFilter(filters: string[]): (log: RollupLog) => boolean;

const VERSION: string;

Utilities

Core Types

interface RollupOptions extends InputOptions {
  output?: OutputOptions | OutputOptions[];
}

interface InputOptions {
  input?: InputOption;
  external?: ExternalOption;
  plugins?: InputPluginOption;
  cache?: boolean | RollupCache;
  treeshake?: boolean | TreeshakingPreset | TreeshakingOptions;
  logLevel?: LogLevelOption;
  onLog?: LogHandlerWithDefault;
  watch?: WatcherOptions | false;
  context?: string;
  fs?: RollupFsModule;
  jsx?: false | JsxPreset | JsxOptions;
  moduleContext?: ((id: string) => string | null) | Record<string, string>;
  perf?: boolean;
  preserveEntrySignatures?: PreserveEntrySignaturesOption;
  preserveSymlinks?: boolean;
  shimMissingExports?: boolean;
  strictDeprecations?: boolean;
  experimentalCacheExpiry?: number;
  experimentalLogSideEffects?: boolean;
  makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
  maxParallelFileOps?: number;
}

interface OutputOptions {
  format?: ModuleFormat;
  file?: string;
  dir?: string;
  plugins?: OutputPluginOption;
  sourcemap?: boolean | 'inline' | 'hidden';
  globals?: GlobalsOption;
  banner?: string | AddonFunction;
  footer?: string | AddonFunction;
  intro?: string | AddonFunction;
  outro?: string | AddonFunction;
  amd?: AmdOptions;
  assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string);
  chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
  compact?: boolean;
  dynamicImportInCjs?: boolean;
  entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
  esModule?: boolean | 'if-default-prop';
  experimentalMinChunkSize?: number;
  exports?: 'default' | 'named' | 'none' | 'auto';
  extend?: boolean;
  externalImportAttributes?: boolean;
  externalLiveBindings?: boolean;
  freeze?: boolean;
  generatedCode?: GeneratedCodePreset | GeneratedCodeOptions;
  hashCharacters?: HashCharacters;
  hoistTransitiveImports?: boolean;
  importAttributesKey?: ImportAttributesKey;
  indent?: string | boolean;
  inlineDynamicImports?: boolean;
  interop?: InteropType | GetInterop;
  manualChunks?: ManualChunksOption;
  minifyInternalExports?: boolean;
  name?: string;
  noConflict?: boolean;
  paths?: OptionsPaths;
  preserveModules?: boolean;
  preserveModulesRoot?: string;
  reexportProtoFromExternal?: boolean;
  sanitizeFileName?: boolean | ((fileName: string) => string);
  sourcemapBaseUrl?: string;
  sourcemapExcludeSources?: boolean;
  sourcemapFile?: string;
  sourcemapFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
  sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption;
  sourcemapPathTransform?: SourcemapPathTransformOption;
  sourcemapDebugIds?: boolean;
  strict?: boolean;
  systemNullSetters?: boolean;
  validate?: boolean;
  virtualDirname?: string;
}

interface RollupOutput {
  output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
}

interface OutputChunk extends RenderedChunk {
  code: string;
  map: SourceMap | null;
  sourcemapFileName: string | null;
  preliminaryFileName: string;
}

interface OutputAsset extends PreRenderedAsset {
  fileName: string;
  needsCodeReference: boolean;
}

interface RollupCache {
  modules: ModuleJSON[];
  plugins?: Record<string, SerializablePluginCache>;
}

type ModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd' | 'commonjs' | 'esm' | 'module' | 'systemjs';
type LogLevel = 'warn' | 'info' | 'debug';
type LogLevelOption = LogLevel | 'silent';
type ChangeEvent = 'create' | 'update' | 'delete';
type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';
type JsxPreset = 'react' | 'react-jsx' | 'preserve' | 'preserve-react';
type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
type InteropType = 'compat' | 'auto' | 'esModule' | 'default' | 'defaultOnly';
type ImportAttributesKey = 'with' | 'assert';
type HashCharacters = 'base64' | 'base36' | 'hex';
type GeneratedCodePreset = 'es5' | 'es2015';
type InputOption = string | string[] | Record<string, string>;
type ExternalOption = (string | RegExp)[] | string | RegExp | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null);
type GlobalsOption = Record<string, string> | ((name: string) => string);
type ManualChunksOption = Record<string, string[]> | GetManualChunk;
type GetManualChunk = (id: string, meta: ManualChunkMeta) => string | null;
type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
type SerializablePluginCache = Record<string, [number, any]>;
type SerializedTimings = Record<string, [number, number, number]>;
type InputPluginOption = MaybePromise<Plugin | null | false | InputPluginOption[]>;
type OutputPluginOption = MaybePromise<OutputPlugin | null | false | OutputPluginOption[]>;
type LogHandlerWithDefault = (level: LogLevel, log: RollupLog, defaultHandler: LogOrStringHandler) => void;
type MaybePromise<T> = T | Promise<T>;