Rolldown

1.0.0-rc.16 · active · verified Sun Apr 19

Rolldown is a high-performance JavaScript and TypeScript bundler written in Rust, aiming to unify and replace esbuild and Rollup in build pipelines like Vite. It offers 10-30x faster builds than Rollup due to its Rust-based, parallel processing architecture. Currently at version `1.0.0-rc.16`, Rolldown is in a Release Candidate phase, signaling API stability with no planned breaking changes before the 1.0 stable release, though experimental features like minification may still have rough edges. It features a Rollup-compatible plugin API, built-in transforms for TypeScript and JSX powered by Oxc, native CJS/ESM interoperability without additional plugins, and granular code splitting akin to Webpack's `optimization.splitChunks`. Rolldown is designed to serve as Vite 8+'s default bundler but can also be used as a standalone tool, offering more control than esbuild when complex chunking is required.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically use Rolldown to bundle a TypeScript project, including basic configuration, output options, and a simple custom plugin.

import { rolldown, defineConfig } from 'rolldown';
import path from 'path';

async function buildMyProject() {
  const inputDir = path.resolve(__dirname, 'src');
  const outputDir = path.resolve(__dirname, 'dist');

  const options = defineConfig({
    input: path.join(inputDir, 'main.ts'),
    output: {
      dir: outputDir,
      format: 'esm',
      entryFileNames: '[name]-[hash].js',
      chunkFileNames: 'chunks/[name]-[hash].js',
      sourcemap: true,
      minify: process.env.NODE_ENV === 'production' ? 'dce-only' : false, // DCE-only minification is default since v1.0.0-rc.7
    },
    plugins: [
      // Example: A simple plugin to log file IDs during resolution
      {
        name: 'log-resolve-id',
        resolveId(source, importer, options) {
          console.log(`Resolving: ${source} (imported by ${importer || 'entry'})`);
          return null; // Let other resolvers handle it
        }
      }
    ],
    // Rolldown handles TypeScript and Node.js module resolution out of the box
    // No need for @rollup/plugin-typescript or @rollup/plugin-node-resolve
    tsconfig: true, // Auto-detect tsconfig.json
  });

  console.log('Starting Rolldown build...');
  const bundle = await rolldown(options);

  console.log('Writing bundle to disk...');
  await bundle.write(options.output);
  console.log('Build complete!');
}

// Run the build process
buildMyProject().catch(console.error);

// Example of an entry file (src/main.ts)
// export * from './utils';
// console.log('Hello from main.ts');

// Example of a utility file (src/utils.ts)
// export const sum = (a: number, b: number) => a + b;

view raw JSON →