webpack, rollup, esbuild, and tsup are tools used to bundle JavaScript code for production. webpack is a mature module bundler with a vast ecosystem, suitable for complex applications. rollup focuses on bundling libraries with clean output and efficient tree-shaking. esbuild is an extremely fast bundler and transpiler written in Go, often used for build steps where speed matters. tsup is a zero-config bundler for TypeScript libraries that uses esbuild under the hood to handle transpilation and type definitions.
Choosing the right build tool affects how fast your code compiles, how easy it is to configure, and how well it scales. webpack, rollup, esbuild, and tsup all solve the problem of packaging code, but they take different approaches. Let's look at how they handle configuration, speed, plugins, and TypeScript.
webpack relies on a dedicated configuration file.
webpack.config.js to define entry points and output.// webpack: webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
}
};
rollup also uses a config file but focuses on bundles.
rollup.config.js to define input and output formats.// rollup: rollup.config.js
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'esm'
}
};
esbuild does not have a built-in config file.
// esbuild: build.js
const esbuild = require('esbuild');
esbuild.build({
entryPoints: ['src/index.js'],
outfile: 'dist/bundle.js',
bundle: true
});
tsup aims for zero configuration.
tsup.config.ts for custom settings.// tsup: tsup.config.ts (optional)
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm']
});
webpack runs on Node.js and can be slow on large projects.
// webpack: Typically run via npm script
// "build": "webpack --mode production"
// Speed depends heavily on loader complexity
rollup is faster than webpack for libraries.
// rollup: Typically run via npm script
// "build": "rollup -c"
// Faster than webpack for ESM output
esbuild is written in Go and compiles to native code.
// esbuild: Run via API or CLI
// "build": "node build.js"
// Extremely fast due to Go implementation
tsup inherits the speed of esbuild.
esbuild, it keeps the performance benefits.// tsup: Run via CLI
// "build": "tsup src/index.ts"
// Near instant builds for TypeScript libraries
webpack has the largest ecosystem of loaders and plugins.
// webpack: Using loaders for CSS
module.exports = {
module: {
rules: [
{ test: /\.css$/, use: ['style-loader', 'css-loader'] }
]
}
};
rollup uses plugins but is more focused on JS transformations.
// rollup: Using plugins
import commonjs from '@rollup/plugin-commonjs';
export default {
plugins: [commonjs()]
};
esbuild has a smaller plugin ecosystem.
// esbuild: Custom plugin example
const myPlugin = {
name: 'my-plugin',
setup(build) {
// Plugin logic here
}
};
tsup relies on esbuild plugins.
esbuild.// tsup: Passing esbuild plugins
export default defineConfig({
esbuildPlugins: [myPlugin]
});
webpack requires loaders to handle TypeScript.
ts-loader or babel-loader.fork-ts-checker.// webpack: TypeScript configuration
module.exports = {
module: {
rules: [
{ test: /\.tsx?$/, use: 'ts-loader' }
]
}
};
rollup needs plugins for TypeScript.
@rollup/plugin-typescript.// rollup: TypeScript plugin
import typescript from '@rollup/plugin-typescript';
export default {
plugins: [typescript()]
};
esbuild supports TypeScript syntax out of the box.
tsc separately if you want type safety.// esbuild: TypeScript support
esbuild.build({
entryPoints: ['src/index.ts'],
loader: { '.ts': 'ts' }
});
tsup handles TypeScript and types automatically.
.d.ts files in one step.// tsup: Automatic d.ts generation
export default defineConfig({
dts: true // Generates type definitions
});
| Feature | webpack | rollup | esbuild | tsup |
|---|---|---|---|---|
| Primary Use | Complex Web Apps | Libraries | Fast Bundling | TS Libraries |
| Config | webpack.config.js | rollup.config.js | JS API / CLI | Zero / tsup.config.ts |
| Speed | Slow | Medium | Very Fast | Very Fast |
| TypeScript | Via Loader | Via Plugin | Syntax Only | Built-in + d.ts |
| Ecosystem | Massive | Large | Growing | Moderate |
webpack is the heavy-duty option 🏗️. It handles everything from legacy code to complex asset pipelines. Use it when you need maximum control and compatibility for large applications.
rollup is the library specialist 📦. It creates clean, efficient bundles for packages others will install. Use it when publishing code to npm.
esbuild is the speed demon 🏎️. It compiles code faster than almost anything else. Use it when build time is a bottleneck or for simple bundling tasks.
tsup is the TypeScript shortcut ⚡. It combines esbuild speed with automatic type handling. Use it when you want to ship TypeScript libraries without configuring build tools.
Final Thought: All four tools can get the job done, but they excel in different areas. Match the tool to your project type — complex apps need webpack, libraries need rollup or tsup, and speed-critical tasks need esbuild.
Choose esbuild if build speed is your top priority and you need a simple bundler or transpiler. It works well for projects that do not require complex code splitting or a heavy plugin ecosystem. It is ideal for internal tools, simple sites, or as the engine behind other tools like Vite.
Choose rollup if you are publishing a JavaScript or TypeScript library to npm. It produces clean output formats like ESM and CJS with excellent tree-shaking. It is the standard choice when you need fine-grained control over how your library code is bundled and distributed.
Choose tsup if you want to bundle a TypeScript library with zero configuration. It handles type definition generation and multiple output formats automatically using esbuild. It is perfect for developers who want the speed of esbuild without writing custom build scripts.
Choose webpack if you are building a complex web application with many assets like images, CSS, and legacy code. It has the largest ecosystem of loaders and plugins for handling specific file types. It is best for large teams that need deep customization and long-term stability.
This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the JavaScript API documentation for details.