Then run webpack on the command-line to create bundle.js.
Awesome, isn't it? Let's dive in!
Get Started quickly in our Guides section, or dig into the Concepts section for more high-level information on the core notions behind webpack.
Comparison
Webpack is not the only module bundler out there. If you are choosing between using webpack or any of the bundlers below, here is a feature-by-feature comparison on how webpack fares against the current competition.
♦ in production mode (opposite in development mode)
X is the length of the path string
Bundling vs. Loading
It's important to note some key differences between loading and bundling modules. A tool like SystemJS, which can be found under the hood of JSPM, is used to load and transpile modules at runtime in the browser. This differs significantly from webpack, where modules are transpiled (through "loaders") and bundled before hitting the browser.
Each method has its advantages and disadvantages. Loading and transpiling modules at runtime can add a lot of overhead for larger sites and applications comprised of many modules. For this reason, SystemJS makes more sense for smaller projects where fewer modules are required. However, this may change a bit as HTTP/2 will improve the speed at which files can be transferred from server to client. Note that HTTP/2 doesn't change anything about transpiling modules, which will always take longer when done client-side.
Awesome webpack
A curated list of awesome webpack resources, libraries, tools and applications. It is inspired by the awesome list. Feel free to improve this list by contributing.
Generate package.json Plugin - Limit dependencies in a deployment package.json to only those that are actually being used by your bundle. -- Maintainer: Paul Myburgh
build-hash-webpack-plugin For each build, Webpack generates an in-memory hash allowing to know if two build outputs are the same or not. This plugin writes the described build hash in a separate json file. -- Maintainer: Réda Housni Alaoui
webpack-hook-plugin - run any shell commands before or after webpack builds -- Maintainer: David Kwon
Dynamic Vendor Webpack Plugin - Gives you a way to import vendors with dynamic variable and specific code splitting. -- MaintainerLilian Saget-Lethias
Define Variable Webpack Plugin - Enhancement of DefinePlugin to store defined things in actual variables. -- MaintainerLilian Saget-Lethias
webpack-typescript-directory-compile-plugin Configure an source directory of typescript files and an output directory for JavaScript files. Each typescript file in the source directory and any newly added files will be compiled to individual JavaScript files. -- Maintainer: Stephen Sigwart
CycloneDX Webpack Plugin: Create CycloneDX Software Bill of Materials (SBOM) from webpack bundles at compile time. -- Maintainer: OWASP CycloneDX Team
Transpile Webpack Plugin: Transpiles input files into output files individually without bundling together. -- Maintainer: Chungen Li
Manifest Extraction Plugin: Generates an asset manifest after compiling webpack. -- Maintainer: Andrew Powell
Transform Async Modules Plugin: A Webpack plugin to transpile async module output using Babel. Allows transpiling top level await to ES5. -- Maintainer: Steve Repsher
Read - A highly scalable react boilerplate from logustra
@route-resource-preload/webpack-plugin - Focus on improving the first screen loading speed of applications and providing the best user experience, inspiration comes from the preloading of NextJS from Devin Deng.
Vue
Vuad - A highly scalable vue boilerplate from logustra
Here you can find webpack project brand guidelines, assets, and license. See our official media repository for more information and to find the license that governs this work. Click any of the images to download them.
The Name
Webpack can be written with a capital W when used at the start of a sentence, otherwise it should be written in lower-case letters.
Logo
The webpack logo should be placed on a white background with enough space around it like this:
The following colors are used throughout the site in various combinations and on our fancy clothing line launched with the help of Open Collective and Threadless over at the official webpack store!
Color Name
HEX Code
RGB Code
Sample
Malibu:
HEX #8dd6f9
rgb: 141, 214, 249
Denim:
HEX #1d78c1
rgb: 29, 120, 193
Fiord:
HEX #465E69
rgb: 70, 94, 105
Outer Space:
HEX #2B3A42
rgb: 43, 58, 66
White:
HEX #ffffff
rgb: 255, 255, 255
Concrete:
HEX #f2f2f2
rgb: 242, 242, 242
Alto:
HEX #dedede
rgb: 222, 222, 222
Dusty Gray:
HEX #999999
rgb: 153, 153, 153
Dove Gray:
HEX #666666
rgb: 102, 102, 102
Emperor:
HEX #535353
rgb: 83, 83, 83
Mine Shaft:
HEX #333333
rgb: 51, 51, 51
In addition, you can grab the following file types directly from these links:
The logo and the brand name are not MIT licensed. Please check our LICENSE for usage guidelines.
Glossary
This index lists common terms used throughout the webpack ecosystem.
A
Asset: This is a general term for the images, fonts, media, and any other kind of files that are typically used in websites and other applications. These typically end up as individual files within the output but can also be inlined via things like the style-loader or url-loader.
B
Bundle: Produced from a number of distinct modules, bundles contain the final versions of source files that have already undergone the loading and compilation process.
Bundle Splitting: This process offers one way of optimizing a build, allowing webpack to generate multiple bundles for a single application. As a result, each bundle can be isolated from changes effecting others, reducing the amount of code that needs to be republished and therefore re-downloaded by the client and taking advantage of browser caching.
C
Chunk: This webpack-specific term is used internally to manage the bundling process. Bundles are composed out of chunks, of which there are several types (e.g. entry and child). Typically, chunks directly correspond with the output bundles however, there are some configurations that don't yield a one-to-one relationship.
Code Splitting: Refers to dividing your code into various bundles/chunks which you can then load on demand instead of loading a single bundle containing everything.
Configuration: webpack configuration file is a plain old JavaScript file that exports an object. This object is then processed by webpack based upon its defined properties.
D
Dependency Graph: Any time one file depends on another, webpack treats this as a dependency. Starting from an entry point(s), webpack recursively builds a dependency graph that includes every module/asset your application needs.
E
Entry Point: The entry point tells webpack where to start and follows the graph of dependencies to know what to bundle. You can think of your application's entry point(s) as the contextual root(s) of what you want bundled.
H
Hot Module Replacement (HMR): A process that exchanges, adds, or removes modules while an application is running without a full page reload.
L
Loaders: Transformations that are applied on the source code of a module. They allow you to pre-process files as you require() or "load" them. Similar to a 'task-runner'.
Lazy Loading: A process of loading parts (chunks) of your application lazily. In other words loading them only when we really need them.
M
Module: Discrete chunks of functionality that provide a smaller surface area than a full program. Well-written modules provide solid abstractions and encapsulation boundaries which make up a coherent design and clear purpose.
Module Resolution: A module can be required as a dependency from another module and a resolver is a library which helps in locating a module by its absolute path. Modules are searched for inside all directories specified in resolve.modules.
Manifest: The runtime will use it to resolve and load modules once they've been bundled and shipped to the browser.
O
Output: Option(s) specifying where to output the compiled files to disk.
Note, that while there can be multiple entry points, only one output configuration is specified.
P
Plugin: A JavaScript object that has an apply property. This apply property is called by the webpack compiler, giving access to the entire compilation lifecycle. These packages will typically extend compilation functionality in one way or another.
R
Request: Refers to the expression in the require/import statement, e.g. require("./template/" + name + ".ejs"), the request is "./template/" + name + ".ejs".
S
Shimming: Not all JS files can be used directly with webpack. The file maybe in an unsupported module format, or not even in any module format. It is here where shimming comes into play.
T
Target: User configured deployment target(s) listed here to compile for a specific environment like the browser, NodeJS, or Electron.
Tree Shaking: Unused/Excess code elimination, or more precisely, live code importing. Compilers like webpack will accomplish this by analyzing the various kinds import statements and usage of the imported code to determine what parts of dependencies are actually being utilized, dropping parts of the "tree" that are not.
V
Vendor Entry Point: Create dependency graphs starting at both app.js and vendors.js. These graphs are completely separate and independent of each other to allow leverage of CommonsChunkPlugin and extract any vendor references from your app bundle into your vendor bundle. Helps achieve a common pattern in webpack known as long-term vendor-caching.
W
webpack: A highly configurable module bundler for modern JavaScript applications.