API Reference
Complete API reference for @vitus-labs/tools-rollup.
CLI
| Command | Description |
|---|---|
vl_build | Production build — runs runBuild() |
vl_build-watch | Watch mode — rebuilds every variant on change |
runBuild()
runBuild(): Promise<void>Orchestrates the complete Rollup build pipeline.
Steps:
- Clean
outputDir - Create build pipeline from
package.jsonfields - Execute each build sequentially with Rollup (the first one also rolls up declarations)
File sizes and visualization reports are produced by plugins during each build.
import { runBuild } from '@vitus-labs/tools-rollup'
await runBuild()Configuration Shape
Read from the build key of vl-tools.config.mjs and deep-merged over the defaults below (nested objects merge, arrays replace).
interface BuildConfig {
sourceDir: string // Entry: <sourceDir>/index (default: 'src')
outputDir: string // Directory cleaned before the build (default: 'lib')
typesDir: string // Intermediate declaration output for API Extractor
typescript: boolean // TypeScript compile + .d.ts rollup
replaceGlobals: boolean // Inject platform globals
filesize: boolean // Console size report
visualise: {
template: string // rollup-plugin-visualizer template
gzipSize: boolean
outputDir: string // Report dir next to each output
} | false
extensions: string[] // Resolved extensions (platform variants are prepended)
include: string[] // tsconfig `include` default for rollup-plugin-typescript2
external: (string | RegExp)[] // Additional externals
exclude: string[] // tsconfig `exclude` default for rollup-plugin-typescript2
globals: Record<string, string> // UMD globals as { GlobalName: 'module-id' }
}esModulesOnly is still present in the defaults but is not read anywhere — module format follows "type" in package.json. Sourcemaps are always emitted and are not configurable.
Default Configuration
{
sourceDir: 'src',
outputDir: 'lib',
typesDir: 'lib/types',
typescript: true,
esModulesOnly: false,
replaceGlobals: true,
filesize: true,
visualise: {
template: 'network',
gzipSize: true,
outputDir: 'analysis',
},
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
include: ['src'],
external: ['react/jsx-runtime'],
exclude: [
'lib',
'node_modules/**',
'**/__tests__/**',
'**/__specs__/**',
'**/__stories__/**',
'*.test.*',
'*.spec.*',
'*.stories.*',
'stories.*',
'*.story.*',
],
globals: {
react: 'React',
ReactDOM: 'react-dom',
styled: 'styled-components',
},
}globals is inverted before it reaches Rollup's output.globals, so each entry is written as GlobalName: 'module-id'.
Rollup Configuration
Every build uses the same base options:
{
input: CONFIG.sourceDir,
makeAbsoluteExternalsRelative: true,
preserveEntrySignatures: 'strict',
external: [...dependencies, ...peerDependencies, ...optionalDependencies, ...CONFIG.external],
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false },
output: {
file,
format, // 'es' | 'cjs' | 'umd'
globals: swapGlobals(CONFIG.globals),
sourcemap: true,
exports: 'named', // cjs and umd only
name: PKG.bundleName, // umd only — camelCase package name
esModule: true,
generatedCode: { reservedNamesAsProps: false },
interop: 'compat',
systemNullSetters: false,
},
}Externals match deep imports too (echarts also matches echarts/core).
Build Pipeline Generation
| Source | Format | Env | Platform |
|---|---|---|---|
exports import | 'es' | development | 'universal' |
exports require | 'cjs' | development | 'universal' |
exports node | 'es' | development | 'node' |
exports default | 'es' | development | 'universal' |
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 mapped field | — | 'browser' |
exports is only read when "type": "module"; for a subpath map, only exports["."] is used. The types path comes from exports["."].types (or nested under import/require/default), then types, then typings, and is attached to the first variant. If a types path is set but no variants are found, a warning is logged and typings are skipped.
Global Type Definitions
The package ships global type declarations for platform constants:
// global/index.d.ts
declare global {
const __BROWSER__: true
const __WEB__: true
const __NATIVE__: true
const __NODE__: true
const __CLIENT__: true
}
declare global {
interface Window {
__BROWSER__: true
__WEB__: true
__NATIVE__: true
__NODE__: true
__CLIENT__: true
}
}Reference these in your tsconfig.json:
{
"compilerOptions": {
"types": ["@vitus-labs/tools-rollup/global"]
}
}Exports
| Entry | Exports |
|---|---|
@vitus-labs/tools-rollup | runBuild |
@vitus-labs/tools-rollup/global | Type declarations only |
import { runBuild } from '@vitus-labs/tools-rollup'Last updated on