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

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 | | :-------------------------------------------------------------------------------------------------------------------------------------------

readme truncated — read the full docs on github

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,945 GitHub stars.