webpack is a free, open source build & deployment project written in JavaScript and released under MIT. It has 65,978 GitHub stars, 9,619 forks and 123 open issues, and was last pushed 12 hours ago. On this registry it ranks #2 of 84 tracked projects in Build & Deployment, with 5 head-to-head comparisons available. It gained 21 stars over the last 30 tracked days.

What is webpack?

What it is

webpack is an open-source module bundler for JavaScript and related assets, distributed under the MIT license and published to npm. It lives in the JavaScript ecosystem, where the README describes its main purpose as bundling JavaScript files for use in a browser, while also being capable of transforming, bundling, or packaging just about any resource or asset. Loaders let modules arrive in many forms — CommonJS, AMD, ES6 modules, CSS, images, JSON, CoffeeScript, LESS, or custom formats — and the plugin system extends what the build can do.

The concrete problem it solves is delivery to the browser. Browsers do not natively consume the mix of module systems that a large application accumulates, and serving every source file separately inflates request count and runtime weight. webpack resolves dependencies during compilation, so what ships is a few bundled assets rather than the whole dependency tree. Code splitting goes further: instead of one monolithic file, the build can emit multiple chunks loaded asynchronously at runtime, reducing initial loading time. Loaders such as TypeScript to JavaScript, Handlebars strings to compiled functions, and images to Base64 handle preprocessing at compile time.

Key capabilities

  • Bundles ES Modules, CommonJS, and AMD modules, including projects that combine them in one build.
  • Produces either a single bundle or multiple chunks that are loaded asynchronously at runtime.
  • Resolves dependencies during compilation, which reduces the runtime size of the output.
  • Applies loaders that preprocess files while compiling, for example TypeScript to JavaScript or images to Base64.
  • Offers a highly modular plugin system for anything else an application requires.
  • Supports code splitting to load parts of an application on demand.
  • Supports all browsers that are ES5-compliant.

Who uses it and how

  • Front-end teams bundle JavaScript for browser delivery, which is the README's stated main purpose.
  • Applications serving several module systems in one codebase rely on webpack to accept ES Modules, CommonJS, and AMD together.
  • Projects with large entry payloads use code splitting so parts of the application load on demand instead of up front.
  • Teams whose source includes TypeScript, Handlebars templates, images, CSS, or LESS route those files through loaders during compilation.
  • Applications with needs beyond the built-in behavior extend the build through the plugin system.

Getting started

Install as a development dependency with npm install --save-dev webpack, or with yarn add webpack --dev. The project hosts documentation, including a Get Started guide and further guides, at https://webpack.js.org.

When to use it — and when not to

webpack fits projects that need a compilation step for mixed module systems or non-JavaScript assets, and it has been maintained for 15 years under the MIT license with 65,948 stars and 9,543 forks. Two documented limits matter for older targets: IE8 and below are not supported, and import() and require.ensure() require Promise, so supporting older browsers means loading a polyfill. The README lists no hosted service and no paid product to compare against, so adopting webpack means running the build tooling yourself as part of your own pipeline.

project readme (upstream, from github) — read inline


[![npm][npm]][npm-url]

[![node][node]][node-url] [![builds1][builds1]][builds1-url] [![dependency-review][dependency-review]][dependency-review-url] [![coverage][cover]][cover-url] pkg.pr.new [![PR's welcome][prs]][prs-url] compatibility-score downloads install-size backers sponsors contributors discussions discord LFX Health Score Agent Friendly

webpack

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.

Table of Contents

Install

Install with npm:

npm install --save-dev webpack

Install with yarn:

yarn add webpack --dev

Introduction

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

  • Bundles ES Modules, CommonJS, and AMD modules (even combined).
  • Can create a single bundle or multiple chunks that are asynchronously loaded at runtime (to reduce initial loading time).
  • Dependencies are resolved during compilation, reducing the runtime size.
  • Loaders can preprocess files while compiling, e.g. TypeScript to JavaScript, Handlebars strings to compiled functions, images to Base64, etc.
  • Highly modular plugin system to do whatever else your application requires.
Learn about webpack through videos!

Get Started

Check out webpack's quick Get Started guide and the other guides.

Browser Compatibility

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.

Concepts

Plugins

Webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack very flexible.

Webpack can generate HTML pages and extract CSS files itself, both experimental — see what that covers, and what still needs a plugin, for CSS and HTML.

Name Status Install Size Description
compression-webpack-plugin compression-npm compression-size Prepares compressed versions of assets to serve them with Content-Encoding
html-bundler-webpack-plugin bundler-npm bundler-size Renders a template (EJS, Handlebars, Pug) with referenced source asset files into HTML.
pug-plugin pug-plugin-npm pug-plugin-size Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug.

Loaders

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.

JavaScript, JSON and assets need no loader, and CSS and HTML have experimental built-in support — but preprocessors and template engines keep their loaders.

JSON
Name Status Install Size Description
cson-npm cson-size Loads and transpiles a CSON file
Transpiling
Name Status Install Size Description
babel-npm babel-size Loads ES2015+ code and transpiles to ES5 using Babel
type-npm type-size Loads TypeScript like JavaScript
coffee-npm coffee-size Loads CoffeeScript like JavaScript
Templating
Name Status Install Size Description
pug-npm pug-size Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular
md-npm md-size Compiles Markdown to HTML
posthtml-npm posthtml-size Loads and transforms a HTML file using PostHTML
hbs-npm hbs-size Compiles Handlebars to HTML
Styling
Name Status Install Size Description
less-npm less-size Loads and compiles a LESS file
sass-npm sass-size Loads and compiles a Sass/SCSS file
stylus-npm stylus-size Loads and compiles a Stylus file
postcss-npm postcss-size Loads and transforms a CSS/SSS file using PostCSS
Frameworks
Name Status Install Size Description
vue-npm vue-size Loads and compiles Vue Components
polymer-npm polymer-size Process HTML & CSS with preprocessor of choice and require() Web Components like first-class modules
angular-npm angular-size Loads and compiles Angular 2 Components
riot-npm riot-size Riot official webpack loader
svelte-npm svelte-size Official Svelte loader

Performance

Webpack uses async I/O and has multiple caching levels. This makes webpack fast and incredibly fast on incremental compilations.

Module Formats

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.

Code Splitting

Webpack allows you to split your codebase into multiple chunks. Chunks are loaded asynchronously at runtime. This reduces the initial loading time.

Optimizations

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.

Developer Tools

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.

Instrumentation
Name Status Description
tapable-tracer tapable-tracer-npm Traces tapable hook execution in real-time and collects structured stack frames. Can export to UML for generating visualizations.

Contributing

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.

For when your change reaches npm, see RELEASE_SCHEDULE.md — patch releases go out as soon as possible, minor releases every 4 weeks on Thursday.

Creating your own plugins and loaders

If you create a loader or plugin, we would > (he/him)

Maintenance

This webpack repository is maintained by the Core Working Group.

Sponsoring

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:

  • Allow the core team to work on webpack
  • Thank contributors if they invested a large amount of time in contributing
  • Support projects in the ecosystem that are of great value for users
  • Support projects that are voted most (work in progress)
  • Infrastructure cost
  • Fees for money handling

Premium Partners

Other Backers and Sponsors

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.

Angular MoonMail MONEI

Gold Sponsors

Become a gold sponsor and get your logo on our README on GitHub with a link to your site.

Silver Sponsors

Become a silver sponsor and get your logo on our README on GitHub with a link to your site.

Bronze Sponsors

Become a bronze sponsor and get your logo on our README on GitHub with a link to your site.

Backers

Become a backer and get your image on our README on GitHub with a link to your site.

<a href="https://opencollective.com/webpack

Frequently asked questions

Is webpack free to use?

webpack is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does webpack do?

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Throug

What is webpack written in?

webpack is primarily written in JavaScript. Its source is publicly available at https://github.com/webpack/webpack, and it has 65,978 GitHub stars.