[![npm][npm]][npm-url]
[![node][node]][node-url]
[![builds1][builds1]][builds1-url]
[![dependency-review][dependency-review]][dependency-review-url]
[![coverage][cover]][cover-url]
[![PR's welcome][prs]][prs-url]
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
- Introduction
- Concepts
- Contributing
- Support
- Current project members
- Sponsoring
- Special Thanks
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 | 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. | ||
| pug-plugin | 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
Transpiling
| Name | Status | Install Size | Description | | :-------------------------------------------------------------------------------------------------------------------------------------------