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 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.
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 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.
Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
Install with npm:
npm install --save-dev webpack
Install with yarn:
yarn add webpack --dev
Webpack is a bundler for modules. The main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
TL;DR
Check out webpack's quick Get Started guide and the other guides.
Webpack supports all browsers that are ES5-compliant (IE8 and below are not supported).
Webpack also needs Promise for import() and require.ensure(). If you want to support older browsers, you will need to load a polyfill before using these expressions.
Webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack very flexible.
| Name | Status | Install Size | Description |
|---|---|---|---|
| mini-css-extract-plugin | Extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. | ||
| compression-webpack-plugin | Prepares compressed versions of assets to serve them with Content-Encoding | ||
| html-bundler-webpack-plugin | Renders a template (EJS, Handlebars, Pug) with referenced source asset files into HTML. | ||
| html-webpack-plugin | Simplifies creation of HTML files (index.html) to serve your bundles | ||
| pug-plugin | Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug. |
Webpack enables the use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. You can easily write your own loaders using Node.js.
Loaders are activated by using loadername! prefixes in require() statements,
or are automatically applied via regex from your webpack configuration.
| Name | Status | Install Size | Description |
|---|---|---|---|
| Loads and transpiles a CSON file |
| Name | Status | Install Size | Description |
|---|---|---|---|
| Loads ES2015+ code and transpiles to ES5 using Babel | |||
| Loads TypeScript like JavaScript | |||
| Loads CoffeeScript like JavaScript |
| Name | Status | Install Size | Description |
|---|---|---|---|
| Exports HTML as string, requires references to static resources | |||
| Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular | |||
| Compiles Markdown to HTML | |||
| Loads and transforms a HTML file using PostHTML | |||
| Compiles Handlebars to HTML |
| Name | Status | Install Size | Description |
|---|---|---|---|
<style> | Add exports of a module as style to DOM | ||
| Loads CSS file with resolved imports and returns CSS code | |||
| Loads and compiles a LESS file | |||
| Loads and compiles a Sass/SCSS file | |||
| Loads and compiles a Stylus file | |||
| Loads and transforms a CSS/SSS file using PostCSS |
Webpack uses async I/O and has multiple caching levels. This makes webpack fast and incredibly fast on incremental compilations.
Webpack supports ES2015+, CommonJS and AMD modules out of the box. It performs clever static analysis on the AST of your code. It even has an evaluation engine to evaluate simple expressions. This allows you to support most existing libraries out of the box.
Webpack allows you to split your codebase into multiple chunks. Chunks are loaded asynchronously at runtime. This reduces the initial loading time.
Webpack can do many optimizations to reduce the output size of your JavaScript by deduplicating frequently used modules, minifying, and giving you full control of what is loaded initially and what is loaded at runtime through code splitting. It can also make your code chunks cache friendly by using hashes.
If you're working on webpack itself, or building advanced plugins or integrations, the tools below can help you explore internal mechanics, debug plugin life-cycles, and build custom tooling.
| Name | Status | Description |
|---|---|---|
| tapable-tracer | Traces tapable hook execution in real-time and collects structured stack frames. Can export to UML for generating visualizations. |
We want contributing to webpack to be fun, enjoyable, and educational for anyone, and everyone. We have a vibrant ecosystem that spans beyond this single repo. We welcome you to check out any of the repositories in our organization or webpack-contrib organization which houses all of our loaders and plugins.
Contributions go far beyond pull requests and commits. Although we love giving you the opportunity to put your stamp on webpack, we also are thrilled to receive a variety of other contributions including:
To get started have a look at our documentation on contributing.
If you create a loader or plugin, we would <3 for you to open source it, and put it on npm. We follow the x-loader, x-webpack-plugin naming convention.
We consider webpack to be a low-level tool used not only individually but also layered beneath other awesome tools. Because of its flexibility, webpack isn't always the easiest entry-level solution, however we do believe it is the most powerful. That said, we're always looking for ways to improve and simplify the tool without compromising functionality. If you have any ideas on ways to accomplish this, we're all ears!
If you're just getting started, take a look at our new docs and concepts page. This has a high level overview that is great for beginners!!
If you have discovered a 🐜 or have a feature suggestion, feel free to create an issue on GitHub.
For information about the governance of the webpack project, see GOVERNANCE.md.
This webpack repository is maintained by the Core Working Group.
Most of the core team members, webpack contributors and contributors in the ecosystem do this open source work in their free time. If you use webpack for a serious task, and you'd like us to invest more time on it, please donate. This project increases your income/productivity too. It makes development and applications faster and it reduces the required bandwidth.
This is how we use the donations:
Before we started using OpenCollective, donations were made anonymously. Now that we have made the switch, we would like to acknowledge these sponsors (and the ones who continue to donate using OpenCollective). If we've missed someone, please send us a PR, and we'll add you to this list.
Become a gold sponsor and get your logo on our README on GitHub with a link to your site.
Become a silver sponsor and get your logo on our README on GitHub with a link to your site.
Become a bronze sponsor and get your logo on our README on GitHub with a link to your site.
Become a backer and get your image on our README on GitHub with a link to your site.
(In chronological order)