Skip to main content
← Guides

Guide

Rollup vs Vite: Library Builds and Alternatives

Updated PkgPulse Team6 min read
0

Rollup vs Vite for apps and npm libraries: compare output control, Vite 8’s Rolldown migration, plugin compatibility, and practical alternatives to Rollup.

Contents

TL;DR

Use Vite for an application with a development server, or a library that benefits from the same frontend workflow. Use Rollup directly when your package depends on its output configuration or specific plugins. Vite 8 uses Rolldown and Oxc rather than Rollup and esbuild. Choosing Vite is therefore a toolchain decision, not another way to run the same Rollup build.

Quick decision table

RequirementStart withWhat to verify
Browser application with HTML, CSS and hot updatesViteFramework plugin and deployment requirements
Component library with a demo applicationVite library modePeer dependencies, CSS delivery and declarations
Existing Rollup library with custom output hooksRollupWhether changing tools solves a measured problem
Alternative to Rollup without a frontend dev serverEvaluate Rolldown directlyPlugin hooks and generated package compatibility
Several entry points or output formatsEither, after a fixture buildPublished exports, chunks and consumer imports

The matrix is a selection aid, not a speed ranking. An application build and an npm package build have different acceptance criteria.

How the relationship changed

Older Vite guides describe Rollup as the production bundler and esbuild as part of development dependency preparation. That description applies to the older toolchain. The Vite migration guide explicitly describes the replacement in Vite 8. Keep the major version in view when copying configuration from another project.

Vite still provides an application workflow around bundling. The production build guide starts with an HTML entry point and also documents library mode. Rollup exposes the bundling configuration directly. Its configuration reference covers entry points, external modules, output formats and chunk behavior.

A shared configuration vocabulary does not guarantee identical output. Test your package in its consumers after changing bundlers. Check module resolution, assets and side effects rather than comparing only whether the build command exits successfully.

When direct Rollup earns its configuration

Keep Rollup when the build configuration expresses requirements you can name: a plugin that performs a required transform, specific chunk naming, or separate outputs for different consumers. Replacing a working build purely to reduce configuration can move those rules into less visible defaults.

A minimal JavaScript package can start with this configuration:

// rollup.config.mjs
export default {
  input: 'src/index.js',
  external: ['react', /^react\//],
  output: [
    { file: 'dist/index.js', format: 'es', sourcemap: true },
    { file: 'dist/index.cjs', format: 'cjs', sourcemap: true },
  ],
};

This example assumes JavaScript input. It does not compile TypeScript or generate declarations. Add those steps deliberately if the package needs them. Externalizing React also requires declaring the appropriate peer dependency in your package metadata.

Do not publish CommonJS just because a template includes it. Identify the consumers that need it. Each output adds a resolution path to test. A package with browser assets may also need CSS exports and asset handling that this minimal example does not supply.

Rollup supports external as a string, array, regular expression or function. That interface lets a package keep its peers out of the bundle. It does not decide which dependencies should be peers. Keep that policy in one build configuration and inspect the artifact for accidental bundled copies.

Vite library mode and its limits

Library mode is useful when you want a library build next to a Vite-powered development page. It avoids maintaining separate app tooling for a component demo. Vite documents build.lib and external dependency configuration in its build guide.

// vite.config.mjs — Vite 8
import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    lib: {
      entry: 'src/index.js',
      formats: ['es', 'cjs'],
      fileName: format => format === 'es' ? 'index.js' : 'index.cjs',
    },
    rolldownOptions: {
      external: ['react', /^react\//],
    },
  },
});

The migration guide deprecates build.rollupOptions in favor of build.rolldownOptions. An older configuration can still contain Rollup terminology without proving that Rollup runs the build. Update that configuration against the documentation for the major version installed in your lockfile.

Library mode does not replace package design. You still own exports, included files, peer dependencies, declaration generation and consumer tests. A demo that runs successfully can hide a missing CSS export or an undeclared dependency because the workspace resolves files that will be absent from the published tarball.

Alternatives to Rollup: choose the layer first

If your real task is building a web application, Vite is the alternative to evaluate first. It supplies the development and asset workflow around the bundler. Comparing its complete application build with a bare Rollup configuration measures different responsibilities.

If you want a bundler with a familiar configuration model, inspect Rolldown. Its compatibility goals are a reason to evaluate it, not a promise that every plugin will work. Vite's migration guide documents differences involving plugin hooks, transforms, minification and configuration.

For an existing library, write down the reason to migrate before choosing a replacement. Useful reasons include a reproducible build bottleneck or a required capability missing from the current tool. Download popularity and a smaller configuration file do not demonstrate that the replacement meets your package contract.

Do not replace an application framework's build system independently unless the framework supports that change. Framework adapters may depend on build hooks and generated manifests beyond the configuration visible in your repository.

Migration notes: a package acceptance fixture

Use this decision matrix to evaluate an alternative before committing the whole repository:

Fixture checkPass conditionFailure points toward
ESM consumerImports only published files and executes the exported functionExports or filename mismatch
CommonJS consumer, if supportedLoads the intended CommonJS artifactModule type or extension mismatch
Peer dependencyRemains external in every supported outputExternal configuration or plugin behavior
Side-effect importRequired registration or CSS still runsIncorrect side-effect assumptions
Secondary entryResolves through the published export mapEntry/chunk/exports mismatch
TypeScript consumerResolves declarations from the installed tarballMissing declarations or type export

Build the same small library using the old and candidate configurations. Pack each result, then install each tarball into a clean consumer outside the source workspace. Exercise public imports, including any supported secondary paths. Run the consumer's normal test and type-check commands.

Set sideEffects: false only when it is true for the published files. A file that registers a global handler or imports required CSS may need to remain included even when none of its exports are referenced. A smaller bundle that silently drops that behavior is a failed migration.

Measure build time only after these checks pass. Keep source, dependency versions, cache state and output requirements identical. Record repeated runs rather than one warm build against one cold build. This guide does not publish a universal speed or bundle-size winner.

When to use which

Choose Vite for an application, or for a library whose development workflow already needs a frontend sandbox. Its library mode is a valid package-building option. Validate published artifacts independently of the sandbox.

Choose Rollup for a build whose output rules and plugins already work, especially when those rules are the reason for the tool. Preserve it until an alternative passes the same consumer checks with a clear benefit.

Evaluate Rolldown directly when you want to change the bundling engine without adopting an application workflow. Treat plugin behavior as a migration task. Keep the existing build available until package consumers pass.

FAQ

Does Vite still use Rollup?

Vite 8 uses Rolldown and Oxc based tools. Earlier Vite versions used Rollup for production bundling. Follow the migration documentation for your installed major version.

Can Vite build an npm library?

Yes. Its documented library mode uses build.lib. Publishing still requires valid package metadata, external dependency decisions and declarations when your consumers need them.

Methodology

This comparison uses official build and migration documentation. The acceptance matrix is an authored review procedure, not a published benchmark. Old download estimates, unsupported output-quality rankings and unverified plugin compatibility guarantees have been removed.

Source notes

See Rolldown vs esbuild for a bundler-focused comparison, Bun vs Vite for runtime and frontend workflow choices, and publint vs Are the Types Wrong for package validation.