API Reference
Complete API reference for @vitus-labs/tools-rolldown.
CLI
| Command | Description |
|---|---|
vl_rolldown_build | Production build — runs runBuild() |
vl_rolldown_build-watch | Watch mode — rebuilds the JS bundles on change (no declarations, no copyFiles) |
runBuild()
runBuild(): Promise<void>Orchestrates the complete build pipeline. Reads configuration, generates build variants, and executes them sequentially.
Steps:
- Clean
outputDir - Create build pipeline from
package.jsonfields (orentries) - Build JS bundles with Rolldown — variants sharing format/env/platform/extension are built together with shared
_chunks/ - Copy
copyFiles - Generate declarations with
rolldown-plugin-dts
File sizes and visualization reports are produced by plugins during step 3.
import { runBuild } from '@vitus-labs/tools-rolldown'
await runBuild()Configuration Shape
interface BuildConfig {
sourceDir: string // Source directory (default: 'src')
outputDir: string // Directory cleaned before the build (default: 'lib')
typescript: boolean // Generate .d.ts files (default: true)
replaceGlobals: boolean // Inject platform globals (default: true)
filesize: boolean // Show file size stats (default: true)
sourcemap: boolean | 'inline' | 'hidden' // JS sourcemaps (default: true)
visualise: {
template: string // rollup-plugin-visualizer template (default: 'network')
gzipSize: boolean // Show gzip sizes
outputDir: string // Report dir next to each output (default: 'analysis')
} | false
extensions: string[] // File extensions to resolve
external: (string | RegExp)[] // Additional externals (replaces the default list)
globals: Record<string, string> // UMD/IIFE globals as { GlobalName: 'module-id' }
// Advanced build options
entries?: Array<{ // Explicit entries (bypasses package.json)
input: string
file: string
format?: 'es' | 'cjs' | 'umd' | 'iife'
env?: 'development' | 'production'
platform?: 'universal' | 'browser' | 'node' | 'native'
}>
bundleAll?: boolean // Bundle all deps, no externals (default: false)
copyFiles?: Array<{ // Copy static files post-build (recursive)
from: string
to: string
}>
banner?: string // Inject at top of output
footer?: string // Inject at bottom of output
alias?: Record<string, string> // Resolve aliases
plugins?: RolldownPlugin[] // Custom plugins (default: [])
}Default Configuration
{
sourceDir: 'src',
outputDir: 'lib',
typescript: true,
replaceGlobals: true,
visualise: {
template: 'network',
gzipSize: true,
outputDir: 'analysis',
},
filesize: true,
sourcemap: true,
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
external: ['react/jsx-runtime'],
globals: {
react: 'React',
ReactDOM: 'react-dom',
styled: 'styled-components',
},
entries: undefined,
bundleAll: false,
copyFiles: undefined,
banner: undefined,
footer: undefined,
alias: undefined,
plugins: [],
}Your vl-tools.config.mjs build object is deep-merged over these defaults: nested objects (visualise, globals) merge key by key, arrays (external, extensions, plugins) replace the default.
globals is inverted before it is passed to Rolldown's output.globals, so each entry is written as GlobalName: 'module-id'.
Build Pipeline Generation
The pipeline is generated from package.json fields (unless entries is set):
exports Field Processing
Read only when "type": "module". Supports a string, a conditions object, or a subpath map (".", "./sub").
| Condition Key | Output Format | Platform |
|---|---|---|
import | 'es' | 'universal' |
require | 'cjs' | 'universal' |
node | 'es' | 'node' |
default | 'es' (only without import) | 'universal' |
Nested conditions are flattened (default → import → require). Wildcard subpaths are skipped with a warning.
Other Fields
| Field | Output Format | Env | Platform |
|---|---|---|---|
main | 'es' with type: "module", otherwise 'cjs' | development | 'universal' |
module | 'es' | development | 'universal' |
react-native | 'es' (only if different from module) | development | 'native' |
umd:main | 'umd' | development | — |
unpkg | 'umd' | production | — |
browser (object map) | same as the mapped field | — | 'browser' |
Variants that resolve to the same file, format, platform and env are de-duplicated.
Build Variant Shape
interface BuildVariant {
file: string // Output file path
format: 'es' | 'cjs' | 'umd' | 'iife'
env: 'development' | 'production'
platform: 'universal' | 'browser' | 'node' | 'web' | 'native'
input?: string // Per-entry input (otherwise sourceDir)
}Plugin Pipeline
Rolldown handles TypeScript, module resolution and global replacement natively (resolve.extensions, transform.define). Plugins added per build:
| Plugin | Condition | Purpose |
|---|---|---|
rollup-plugin-visualizer | visualise not false | Bundle composition HTML |
filesize (from @vitus-labs/tools-core) | filesize: true | Console file size reporting (gzip of emitted bytes) |
your plugins | always | Appended after the built-ins |
Declarations are built in separate Rolldown calls with rolldown-plugin-dts (emitDtsOnly, no sourcemaps).
Platform-Specific Extensions
For platform "browser", the resolver checks (in order):
.browser.json, .browser.js, .browser.jsx, .browser.ts, .browser.tsx,
.browser.es6, .browser.es, .browser.mjs,
.json, .js, .jsx, .ts, .tsx, .es6, .es, .mjsSame pattern applies to node, web, and native platforms. universal uses only the base extensions.
Output Configuration
Common to every build:
{
format, // 'es' | 'cjs' | 'umd' | 'iife'
globals: swapGlobals(CONFIG.globals),
sourcemap: CONFIG.sourcemap, // node_modules sources are ignore-listed
exports: 'named', // cjs, umd, iife only
name: PKG.bundleName, // umd, iife only — camelCase package name
esModule: true,
minify: env === 'production',
banner: CONFIG.banner,
footer: CONFIG.footer,
}Input side: platform maps to Rolldown's 'node', 'browser' or 'neutral'; tsconfig: 'tsconfig.json' when typescript is on; treeshake.moduleSideEffects: false.
Global Type Definitions
{
"compilerOptions": {
"types": ["@vitus-labs/tools-rolldown/global"]
}
}Declares __BROWSER__, __WEB__, __NATIVE__, __NODE__ and __CLIENT__ as globals (and on Window).
Exports
| Entry | Exports |
|---|---|
@vitus-labs/tools-rolldown | runBuild |
@vitus-labs/tools-rolldown/global | Type declarations only |
import { runBuild } from '@vitus-labs/tools-rolldown'Last updated on