— Tooling · @vitus-labs/tools-rolldown
Ship a library from package.json.
vl_rolldown_build reads exports, main, module and the other fields you already publish, builds every bundle they point at with Rolldown, and generates bundled declarations for each types path. Dependencies and peers stay external without a list to maintain.
npm i -D @vitus-labs/tools-rolldown- rolldown configs to write
- 0
- platform globals replaced at build time
- 6
- formats, picked per field
- ESM · CJS · UMD
- Node.js
- ≥ 22
— Why tools · rolldown
The paths are already written down.
package.json is the build config
exports.import becomes an ESM bundle, require a CJS one, unpkg a minified UMD. Each subpath export builds from src/<name> by convention, so the output paths live in one place: the manifest your users resolve.
Declarations, bundled
Every types path gets one bundled .d.ts from rolldown-plugin-dts. Subpaths that share an output directory are generated in a single pass, with common types in _dts_chunks/ instead of copied into each entry.
Externals you never list
Everything in dependencies, peerDependencies and optionalDependencies is external, deep imports included (echarts/core), and node: builtins always are. Only devDependencies get bundled.
One source, several platforms
__WEB__, __NATIVE__, __BROWSER__ and friends are replaced per build, and browser and React Native builds resolve .browser.ts or .native.ts files first.
— Before / after
Write the paths once.
A package with a main entry and a ./devtools subpath, ESM plus types. By hand, the entries, externals and output directories are repeated in a config that has to agree with exports.
import { defineConfig } from 'rolldown'
import { dts } from 'rolldown-plugin-dts'
import pkg from './package.json' with { type: 'json' }
const input = { index: 'src/index.ts', devtools: 'src/devtools.ts' }
const external = [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
].map((id) => new RegExp(`^${id}(/|$)`))
export default defineConfig([
{
input,
external: [...external, /^node:/],
transform: { define: { __VERSION__: JSON.stringify(pkg.version) } },
output: { dir: 'lib', format: 'es', sourcemap: true },
},
{
input,
external: [...external, /^node:/],
plugins: [dts({ dtsOnly: true })],
output: { dir: 'lib/types', format: 'es' },
},
])
// package.json: "build": "rm -rf lib && rolldown -c"Two builds (JS and declarations), externals derived by hand, and the output layout duplicated from package.json.
{
"type": "module",
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/index.js"
},
"./devtools": {
"types": "./lib/types/devtools.d.ts",
"import": "./lib/devtools.js"
}
},
"scripts": {
"build": "vl_rolldown_build",
"dev": "vl_rolldown_build-watch"
}
}The exports map already says where everything goes. Sources come from src/index and src/devtools by convention.
— Features
What one command does.
- vl_rolldown_build
cleans the output directory, builds every bundle, then the declarations
- vl_rolldown_build-watch
rebuilds the JS bundles on change through Rolldown's watcher
- Subpath exports
./devtoolsbuilds fromsrc/devtools; wildcard subpaths are skipped with a warning - Shared chunks
entries with the same format and platform build in one pass, with common code in
_chunks/ - Format per field
import→ ESM,require→ CJS,umd:main→ UMD,unpkg→ minified UMD - browser · react-native
the object form of
browserand a distinctreact-nativepath each get their own build - sourcemap
true,hidden,inlineorfalsefor JS; declarations never get maps - Bundle reports
a rollup-plugin-visualizer page per bundle in
analysis/, raw and gzip sizes in the log - entries · bundleAll
explicit entries and fully bundled output for CLIs, extensions and serverless code
- copyFiles · banner · alias
copy static files, add a shebang or license header, remap imports
- vl-tools.config.mjs
found from the package up to the repo root and deep-merged; the closest file wins
— API
Two commands. One function.
Every name links to its reference in the docs.
— Honest limits
Where it stops helping.
Where it isn't the right fit, and what to reach for instead.
Side-effect-only imports
Builds tree-shake with
moduleSideEffects: false, so a module imported only for its side effects (a polyfill, a registration call) is dropped. Make the effect reachable from an export, or build that package with Rolldown directly.Watch mode skips declarations
vl_rolldown_build-watchrebuilds the JS bundles only. Runtsc --watchnext to it if you need fresh types while developing, or rerun the full build.TypeScript 7.0 prints a notice
With TypeScript 7.0, rolldown-plugin-dts prints a deprecation notice recommending 7.1 or newer. Declarations are still emitted; the notice goes away when you move to 7.1.
Apps and dev servers
It builds TypeScript libraries: no HTML entry, no dev server, no HMR. For an app use Vite, or Next.js with
@vitus-labs/tools-nextjs.Node 20 or older
The package declares
node >= 22. On older Node, stay on your current bundler until you upgrade.
— Recipes
Copy, paste, ship.
ESM and CommonJS from one exports map
Each condition is one bundle. types drives the declarations; require adds a CJS build next to the ESM one.
{
"name": "@acme/dates",
"type": "module",
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
}
},
"scripts": { "build": "vl_rolldown_build" }
}Platform branches without runtime checks
Add the global types once. A separate react-native path gets its own build where __NATIVE__ is replaced with true; in the web build it is false.
// tsconfig.json → "types": ["@vitus-labs/tools-rolldown/global"]
import { nativeStorage } from './storage.native-impl'
import { webStorage } from './storage.web-impl'
export const storage = __NATIVE__ ? nativeStorage : webStorage
// package.json
// "module": "lib/index.js",
// "react-native": "lib/index.native.js"A self-contained CLI
Explicit entries bypass package.json detection. bundleAll inlines every dependency, and the banner adds the shebang.
export default {
build: {
entries: [
{ input: 'src/cli.ts', file: 'dist/cli.js', format: 'es', platform: 'node' },
],
bundleAll: true,
banner: '#!/usr/bin/env node',
typescript: false,
visualise: false,
},
}— FAQ
Questions, answered.
Do I need a config file at all?
No. With typed exports in package.json and a tsconfig.json in the package root, the defaults cover it. vl-tools.config.mjs (key build) is for overrides such as sourcemap, external or entries.
Which dependencies end up in my bundle?
Only devDependencies. Your own external option replaces the default extra list (react/jsx-runtime), but never the externals derived from package.json or the node: rule.
How does it relate to tools-rollup?
It is the Rolldown-based alternative to @vitus-labs/tools-rollup. It also works on TypeScript 7, which tools-rollup does not: tools-rollup needs TypeScript 5 or 6.
Is it used in production?
Every package of the Vitus Labs UI system is built with vl_rolldown_build.
— @vitus-labs/tools-rolldown
Declare the outputs. Run one command.
npm i -D @vitus-labs/tools-rolldownSources · 34 claims, each traced to v2.9.1 code or docs
- Two CLI commands: vl_rolldown_build and vl_rolldown_build-watchtools:packages/rolldown/package.json
- Requires Node.js >= 22tools:packages/rolldown/package.json
- Build tool for TypeScript libraries; Rolldown alternative to tools-rolluptools:packages/rolldown/README.md
- Field → format table (import ESM, require CJS, umd:main UMD, unpkg minified UMD)tools:packages/rolldown/README.md
- unpkg builds use the production env (minified)tools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Minification only for production variantstools:packages/rolldown/src/rolldown/config.ts
- require condition builds CJStools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Subpath exports resolve to src/<name> by conventiontools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Wildcard subpaths skipped with a warningtools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Declarations generated per types path with rolldown-plugin-dts (dtsOnly)tools:packages/rolldown/src/rolldown/config.ts
- Grouped declaration entries built in a single pass; shared types in _dts_chunks/tools:packages/rolldown/src/scripts/build.ts
- Declarations never get sourcemapstools:packages/rolldown/src/config/baseConfig.ts
- Sourcemap modes true / hidden / inline / falsetools:packages/rolldown/src/config/baseConfig.ts
- dependencies, peerDependencies and optionalDependencies are external, including deep importstools:packages/core/src/index.ts
- Bare package names expand to match deep imports (echarts → echarts/core)tools:packages/core/src/index.ts
- node: builtins always external, even with a custom external listtools:packages/rolldown/src/rolldown/config.ts
- User external replaces the default list (react/jsx-runtime) wholesaletools:packages/rolldown/src/config/baseConfig.ts
- Six platform globals replaced at build time (__VERSION__, __NODE__, __WEB__, __BROWSER__, __NATIVE__, __CLIENT__)tools:packages/rolldown/src/rolldown/config.ts
- Platform-prefixed extensions (.native.ts, .browser.ts) resolved firsttools:packages/rolldown/src/rolldown/config.ts
- Global type declarations at @vitus-labs/tools-rolldown/globaltools:packages/rolldown/package.json
- Separate react-native build only when its path differs from moduletools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Object form of browser maps get their own buildstools:packages/rolldown/src/rolldown/createBuildPipeline.ts
- Entries with the same format/env/platform build together with shared chunks in _chunks/tools:packages/rolldown/src/scripts/build.ts
- Output directory cleaned before building; JS bundles first, then declarationstools:packages/rolldown/src/scripts/build.ts
- Visualizer report per bundle in analysis/; filesize loggingtools:packages/rolldown/src/config/baseConfig.ts
- entries, bundleAll, copyFiles, banner, footer, alias, plugins optionstools:packages/rolldown/README.md
- Cascading vl-tools.config.mjs, root first, closest winstools:packages/core/src/index.ts
- Build reads config under the build keytools:packages/rolldown/src/config/index.ts
- tsconfig.json in the package root is used when typescript is ontools:packages/rolldown/src/rolldown/config.ts
- Tree-shaking with moduleSideEffects: falsetools:packages/rolldown/src/rolldown/config.ts
- Watch mode runs only the JS build configs (no declaration step)tools:packages/rolldown/src/bin/run-watch.ts
- TypeScript 7.0: rolldown-plugin-dts prints a deprecation notice recommending 7.1+; declarations still emittedtools:packages/rolldown/CHANGELOG.md
- tools-rollup needs TypeScript 5/6tools:packages/mcp/src/versions.ts
- The UI system packages build with vl_rolldown_buildui-system:packages/styler/package.json