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-rollupRequirements
- Node.js
>= 22(declared inengines). - 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 buildComparison with tools-rolldown
| Feature | tools-rollup | tools-rolldown |
|---|---|---|
| Bundler | Rollup v4 | Rolldown v1 (Rust) |
| CLI commands | vl_build, vl_build-watch | vl_rolldown_build, vl_rolldown_build-watch |
| TypeScript | rollup-plugin-typescript2 + ts-patch | Built-in Rolldown TS |
| TypeScript peer | ^5.0.0 || ^6.0.0 (no TS 7) | none — works with TS 7 |
| Type generation | @microsoft/api-extractor | rolldown-plugin-dts |
| Runtime dependencies | 13 | 5 |
| Path transforms | typescript-transform-paths | Rolldown native |
Subpath exports (./sub) | Root "." entry only | Every subpath, with shared chunks |
Configurable sourcemap | No (always on) | Yes |
entries, bundleAll, copyFiles, banner, footer, alias, plugins | No | Yes |
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_buildvl_build-watch
Watch mode (development) — rebuilds every variant on change using Rollup's watcher. Stop with Ctrl+C.
vl_build-watchConfiguration
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 field | Format | Platform |
|---|---|---|
exports (import) | ESM | universal |
exports (require) | CJS | universal |
exports (node) | ESM | node |
exports (default) | ESM | universal |
main | CJS, or ESM with "type": "module" | universal |
module | ESM | universal |
react-native | ESM (only if different from module) | native |
browser (object map) | same as mapped field | browser |
umd:main | UMD | — |
unpkg | UMD, minified | — |
exportsis read only when"type": "module". It may be a string, a conditions object, or a subpath map — in which case only the rootexports["."]entry is built. Nested conditions such asimport: { types, default }resolve to theirdefault.- The
requirecondition always produces CommonJS, even in ESM-only packages. - Variants writing the same file in the same format are built once.
browseronly produces builds for its object form with"./…": "./…"string values;falsevalues and the string form are ignored.
Plugin Pipeline
| Order | Plugin | Condition | Purpose |
|---|---|---|---|
| 1 | @rollup/plugin-node-resolve | Always | Resolve modules with platform-specific extensions |
| 2 | rollup-plugin-typescript2 | typescript: true | TypeScript compilation with ts-patch |
| 3 | rollup-plugin-api-extractor | typescript: true and a types path in package.json (first build only) | Roll up .d.ts files |
| 4 | @rollup/plugin-replace | replaceGlobals: true | Inject platform constants |
| 5 | rollup-plugin-visualizer | visualise not false | Bundle visualization |
| 6 | @rollup/plugin-terser | Production env | Minification |
| 7 | filesize (from @vitus-labs/tools-core) | filesize: true | Console 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:
typescript-transform-paths— resolves path aliases in compiled JStypescript-transform-paths(afterDeclarations) — resolves aliases in.d.tsfiles
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
| Format | Exports | Name | Use Case |
|---|---|---|---|
es | — | — | Modern ESM consumers |
cjs | named | — | CommonJS/Node.js |
umd | named | PKG.bundleName | Browser <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):
- Clean
outputDir - Build each variant from
package.jsonwith Rollup - The first variant also rolls up the declarations
Last updated on