Skip to Content
vitus·labs
Tools Rollup

Tools Rollup

Rollup-based build tool for library packages — the predecessor to tools-rolldown.

@vitus-labs/tools-rollup is the legacy build tool using Rollup. For new projects, prefer tools-rolldown which uses the faster Rust-based Rolldown bundler.

Installation

npm install @vitus-labs/tools-rollup

Requirements

  • Node.js >= 22 (declared in engines).
  • Peer dependency: typescript ^5.0.0 || ^6.0.0.

TypeScript 7 is not supported. The TypeScript plugins this package uses (rollup-plugin-typescript2, ts-patch) rely on the TypeScript JavaScript API, which TypeScript 7 no longer ships. Use tools-rolldown with TypeScript 7.

Quick Start

{
  "scripts": {
    "build": "vl_build",
    "dev": "vl_build-watch"
  }
}
bun run build

Comparison with tools-rolldown

Featuretools-rolluptools-rolldown
BundlerRollup v4Rolldown v1 (Rust)
CLI commandsvl_build, vl_build-watchvl_rolldown_build, vl_rolldown_build-watch
TypeScriptrollup-plugin-typescript2 + ts-patchBuilt-in Rolldown TS
TypeScript peer^5.0.0 || ^6.0.0 (no TS 7)none — works with TS 7
Type generation@microsoft/api-extractorrolldown-plugin-dts
Runtime dependencies135
Path transformstypescript-transform-pathsRolldown native
Subpath exports (./sub)Root "." entry onlyEvery subpath, with shared chunks
Configurable sourcemapNo (always on)Yes
entries, bundleAll, copyFiles, banner, footer, alias, pluginsNoYes

Both tools read the build key of vl-tools.config.mjs and derive their outputs from package.json the same way, but the option sets differ — see Configuration.

CLI Commands

vl_build

Production build:

vl_build

vl_build-watch

Watch mode (development) — rebuilds every variant on change using Rollup's watcher. Stop with Ctrl+C.

vl_build-watch

Configuration

Uses the build key in vl-tools.config.mjs. Config files cascade from the current directory upward and are deep-merged (closest file wins; arrays replace defaults):

// vl-tools.config.mjs
export default {
  build: {
    sourceDir: 'src',           // Source directory (default: 'src')
    outputDir: 'lib',           // Directory cleaned before each build (default: 'lib')
    typesDir: 'lib/types',      // Where tsc emits intermediate declarations (default: 'lib/types')
    typescript: true,           // Compile with TypeScript + roll up .d.ts (default: true)
    replaceGlobals: true,       // Inject platform globals (default: true)
    filesize: true,             // Show file sizes in console (default: true)
    visualise: {                // Bundle visualization, or `false` to disable
      template: 'network',
      gzipSize: true,
      outputDir: 'analysis',
    },
    external: ['react/jsx-runtime'],  // Extra externals (replaces the default list)
  },
}

See the API reference for every option and its default.

Output Format Detection

package.json fieldFormatPlatform
exports (import)ESMuniversal
exports (require)CJSuniversal
exports (node)ESMnode
exports (default)ESMuniversal
mainCJS, or ESM with "type": "module"universal
moduleESMuniversal
react-nativeESM (only if different from module)native
browser (object map)same as mapped fieldbrowser
umd:mainUMD—
unpkgUMD, minified—
  • exports is read only when "type": "module". It may be a string, a conditions object, or a subpath map — in which case only the root exports["."] entry is built. Nested conditions such as import: { types, default } resolve to their default.
  • The require condition always produces CommonJS, even in ESM-only packages.
  • Variants writing the same file in the same format are built once.
  • browser only produces builds for its object form with "./…": "./…" string values; false values and the string form are ignored.

Plugin Pipeline

OrderPluginConditionPurpose
1@rollup/plugin-node-resolveAlwaysResolve modules with platform-specific extensions
2rollup-plugin-typescript2typescript: trueTypeScript compilation with ts-patch
3rollup-plugin-api-extractortypescript: true and a types path in package.json (first build only)Roll up .d.ts files
4@rollup/plugin-replacereplaceGlobals: trueInject platform constants
5rollup-plugin-visualizervisualise not falseBundle visualization
6@rollup/plugin-terserProduction envMinification
7filesize (from @vitus-labs/tools-core)filesize: trueConsole size reporting

The TypeScript, replace and terser plugins are loaded lazily, only when a build needs them.

TypeScript Compilation

Uses ts-patch compiler with two transforms:

  1. typescript-transform-paths — resolves path aliases in compiled JS
  2. typescript-transform-paths (afterDeclarations) — resolves aliases in .d.ts files

Type Generation

Uses @microsoft/api-extractor to consolidate the declarations emitted into typesDir (entry typesDir/index.d.ts) into a single rolled-up file at the path from package.json — exports["."].types (also nested under import/require/default), types or typings. Only the first build variant generates types.

Output Formats

FormatExportsNameUse Case
es——Modern ESM consumers
cjsnamed—CommonJS/Node.js
umdnamedPKG.bundleNameBrowser <script> tags

Platform Globals

Same as tools-rolldown — injects __VERSION__, __WEB__, __NATIVE__, __BROWSER__, __NODE__, __CLIENT__ based on platform, plus process.env.NODE_ENV for production builds. Type declarations:

{
  "compilerOptions": {
    "types": ["@vitus-labs/tools-rollup/global"]
  }
}

External Dependencies

dependencies, peerDependencies and optionalDependencies are external, including their deep imports, plus anything in external.

Build Pipeline

Builds execute sequentially (not in parallel):

  1. Clean outputDir
  2. Build each variant from package.json with Rollup
  3. The first variant also rolls up the declarations
Edit on GitHub

Last updated on

On this page