browserify, esbuild, rollup, and webpack are tools designed to bundle JavaScript modules for the browser or Node.js environments, handling dependencies, transpilation, and optimization. pkg serves a distinct purpose by packaging Node.js applications into standalone executable binaries for deployment. While webpack offers a comprehensive plugin ecosystem for complex applications, rollup excels at bundling libraries with efficient tree-shaking. esbuild prioritizes extreme build speed using a Go-based architecture, and browserify remains a lightweight option for simple CommonJS bundling. pkg is unique in this group as it focuses on distribution rather than bundling for the web.
When architecting a JavaScript project, selecting the right build tool impacts everything from developer experience to production performance. browserify, esbuild, rollup, webpack, and pkg all solve dependency management, but they target different stages of the software lifecycle. Let's compare how they handle bundling, configuration, and deployment.
esbuild is built with Go and focuses on raw speed.
// esbuild: CLI usage for bundling
const esbuild = require('esbuild');
esbuild.build({
entryPoints: ['src/app.js'],
bundle: true,
outfile: 'dist/bundle.js',
minify: true
}).catch(() => process.exit(1));
webpack prioritizes flexibility over raw speed.
esbuild but handles complex asset pipelines better.// webpack: webpack.config.js
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
},
mode: 'production'
};
rollup optimizes for ES modules and tree-shaking.
webpack for libraries but slower than esbuild.// rollup: rollup.config.js
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
}
};
browserify uses a streaming approach for CommonJS.
// browserify: CLI or API
const browserify = require('browserify');
browserify('./src/app.js')
.bundle()
.pipe(require('fs').createWriteStream('./dist/bundle.js'));
pkg does not bundle for the web; it compiles Node.js apps.
// pkg: package.json configuration
{
"name": "my-tool",
"version": "1.0.0",
"bin": "index.js",
"pkg": {
"targets": ["node18-linux", "node18-win"]
}
}
webpack requires explicit configuration for most features.
// webpack: Handling CSS
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
};
rollup uses a simpler config focused on output formats.
// rollup: Multiple outputs
export default {
input: 'src/main.js',
output: [
{ file: 'pkg/index.js', format: 'cjs' },
{ file: 'pkg/index.mjs', format: 'es' }
]
};
esbuild keeps configuration minimal and API-driven.
// esbuild: Plugin example
const plugin = {
name: 'example',
setup(build) {
build.onLoad({ filter: /.*/ }, () => ({ contents: '' }));
},
};
await esbuild.build({ plugins: [plugin] });
browserify relies on transforms via the command line or API.
package.json.// browserify: Using a transform
browserify('./app.js')
.transform('babelify')
.bundle();
pkg configuration lives in package.json.
// pkg: Specifying assets
"pkg": {
"scripts": "dist/**/*.js",
"assets": "views/**/*"
}
rollup is the industry standard for tree-shaking.
// rollup: Input
import { utilA } from './utils';
console.log(utilA()); // utilB is removed if unused
webpack supports tree-shaking but can be verbose.
sideEffects: false in package.json for best results.rollup.// webpack: package.json hint
{
"sideEffects": false
}
esbuild performs aggressive tree-shaking by default.
rollup.// esbuild: Minify and tree-shake
esbuild.build({
minify: true,
treeShaking: true
});
browserify has limited tree-shaking capabilities.
uglifyify for minification.// browserify: Minification via pipeline
browserify('app.js')
.transform('uglifyify')
.bundle();
pkg does not perform tree-shaking in the same way.
// pkg: No tree-shaking config
// It packages the whole project folder specified
webpack, rollup, esbuild, and browserify target the browser or Node.js runtime.
// All bundlers: Output is JS
// dist/bundle.js -> Served via Nginx, Vercel, etc.
pkg targets standalone execution.
.exe or binary that runs without Node installed.# pkg: Command to build binary
pkg index.js --targets node18-linux-x64
# Output: index-linux-x64
webpack has the largest ecosystem.
// webpack: Compression Plugin
const CompressionPlugin = require('compression-webpack-plugin');
plugins: [new CompressionPlugin()]
rollup has a strong plugin set for libraries.
webpack.// rollup: TypeScript Plugin
import typescript from '@rollup/plugin-typescript';
plugins: [typescript()]
esbuild has a growing but smaller plugin ecosystem.
webpack.// esbuild: SASS Plugin (example)
await esbuild.build({
plugins: [sassPlugin()]
});
browserify relies on transforms.
// browserify: Envify transform
browserify('app.js').transform('envify')
pkg has minimal plugins.
package.json fields.// pkg: No plugin system
// Configuration is limited to paths and targets
| Feature | webpack | rollup | esbuild | browserify | pkg |
|---|---|---|---|---|---|
| Primary Use | Web Apps | Libraries | Fast Bundling | Legacy/Simple Bundling | Node Executables |
| Speed | Moderate | Fast | Very Fast | Moderate | Slow (includes runtime) |
| Config Style | Complex JS Object | Simple JS Object | API/CLI | CLI/Transforms | package.json |
| Tree-Shaking | Good (with config) | Excellent | Excellent | Limited | N/A |
| Output | JS/CSS/Assets | JS Libraries | JS/Assets | JS | Binary Executable |
| Maintenance | Active | Active | Active | Maintenance Mode | Active |
webpack remains the heavy-duty choice 🏗️ for complex web applications where you need to manage many asset types and require a mature ecosystem. It is the safe, standard choice for enterprise frontend teams.
rollup is the specialist 📚 for library authors who need clean, efficient ES module output. If you are publishing a package to npm, this is often the best fit.
esbuild is the speed demon 🏎️ for teams prioritizing developer experience and build times. It is increasingly used in production, especially when paired with tools that handle what it doesn't.
browserify is the legacy tool 🕰️ that paved the way. While still functional, it lacks modern features like built-in TypeScript support or aggressive optimization, making it less ideal for new greenfield projects.
pkg is the distributor 📦 for Node.js applications. It solves a completely different problem than the others by removing the need for a Node.js installation on the target machine.
Final Thought: For modern frontend development, esbuild and webpack dominate the application space, while rollup owns the library space. Use pkg only when you need to ship a Node.js backend tool as a binary.
Choose rollup if you are building a JavaScript library or framework that needs to be published to npm. It produces cleaner output with superior tree-shaking for ES modules. It is less suited for complex web applications with heavy asset management compared to webpack, but excels in library distribution.
Choose browserify if you maintain a legacy project that relies heavily on CommonJS modules without needing modern transpilation features. It is lightweight and works well for simple scripts where a heavy build system is unnecessary. However, for new projects, modern alternatives like esbuild or webpack are generally preferred due to better TypeScript support and performance.
Choose esbuild if build speed is your primary concern and you need a fast bundler or transpiler for modern JavaScript and TypeScript. It is ideal for development servers where hot module replacement needs to be instant. Be aware that its plugin ecosystem is younger compared to webpack, so complex custom requirements might need workarounds.
Choose pkg if you need to distribute a Node.js command-line tool or backend service as a single standalone executable file. It is not suitable for frontend web bundling. This tool is specific to scenarios where you want to avoid requiring users to install Node.js separately to run your application.
Choose webpack if you are building a complex web application that requires extensive asset management, code splitting, and a mature plugin ecosystem. It handles CSS, images, and various module formats out of the box. It is the safest bet for large-scale enterprise applications where long-term support and community resources are critical.
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application. It uses the standardized ES module format for code, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. Rollup can optimize ES modules for faster native loading in modern browsers, or output a legacy module format allowing ES module workflows today.
Install with npm install --global rollup. Rollup can be used either through a command line interface with an optional configuration file or else through its JavaScript API. Run rollup --help to see the available options and parameters. The starter project templates, rollup-starter-lib and rollup-starter-app, demonstrate common configuration options, and more detailed instructions are available throughout the user guide.
These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.
For browsers:
# compile to a <script> containing a self-executing function
rollup main.js --format iife --name "myBundle" --file bundle.js
For Node.js:
# compile to a CommonJS module
rollup main.js --format cjs --file bundle.js
For both browsers and Node.js:
# UMD format requires a bundle name
rollup main.js --format umd --name "myBundle" --file bundle.js
Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place isn't necessarily the answer. Unfortunately, JavaScript has not historically included this capability as a core feature in the language.
This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the --experimental-modules flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to write future-proof code, and you also get the tremendous benefits of...
In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.
For example, with CommonJS, the entire tool or library must be imported.
// import the entire utils object with CommonJS
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
But with ES modules, instead of importing the whole utils object, we can just import the one ajax function we need:
// import the ajax function with an ES import statement
import { ajax } from 'node:utils';
var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);
Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit import and export statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.
Rollup can import existing CommonJS modules through a plugin.
To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ES-module-aware tools like Rollup and webpack will import the ES module version directly.
This project exists thanks to all the people who contribute. [Contribute]. . If you want to contribute yourself, head over to the contribution guidelines.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
TNG has been supporting the work of Lukas Taegert-Atkinson on Rollup since 2017.