Additional chunks are loaded on demand
yes
src/index.js
import bar from './bar';
bar();
src/bar.js
export default function bar() {
//
}
Without config or provide custom webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
}
};
page.html
<!doctype html>
<html>
<head>
...
</head>
<body>
...
<script src="dist/bundle.js"></script>
</body>
</html>
Then run webpack
on the command-line to create bundle.js
.
Get Started quickly in our Guides section, or dig into the Concepts section for more high-level information on the core notions behind webpack.
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.
Feature | webpack/webpack | jrburke/requirejs | substack/node-browserify | jspm/jspm-cli | rollup/rollup | brunch/brunch |
---|---|---|---|---|---|---|
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Additional chunks are loaded on demand yes |
yes | yes | no | System.import | no | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch AMD yes |
yes | yes | deamdify | yes | rollup-plugin-amd | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch AMD yes |
yes | yes | no | yes | no | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch AMD yes |
yes | with manual configuration | no | yes | no | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch CommonJS yes |
yes | only wrapping in
define |
yes | yes | commonjs-plugin | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch CommonJS yes |
yes | only wrapping in
define |
yes | yes | commonjs-plugin | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch CommonJS yes |
yes | no | no | no | no | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Concat in require yes |
yes | no♦ | no | no | no | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Debugging support SourceUrl, SourceMaps |
SourceUrl, SourceMaps | not required | SourceMaps | SourceUrl, SourceMaps | SourceUrl, SourceMaps | SourceMaps |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Dependencies 19MB / 127 packages |
19MB / 127 packages | 11MB / 118 packages | 1.2MB / 1 package | 26MB / 131 packages | ?MB / 3 packages | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch ES2015 yes (webpack 2) |
yes (webpack 2) | no | no | yes | yes | yes, via es6 module transpiler |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Expressions in require (guided) yes (all files matching included) |
yes (all files matching included) | no♦ | no | no | no | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Expressions in require (free) with manual configuration |
with manual configuration | no♦ | no | no | no | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Generate a single bundle yes |
yes | yes♦ | yes | yes | yes | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Indirect require yes |
yes | no♦ | no | no | no | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Load each file separate no |
no | yes | no | yes | no | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Mangle path names yes |
yes | no | partial | yes | not required (path names are not included in the bundle) | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Minimizing terser |
terser | uglify, closure compiler | uglifyify | yes | uglify-plugin | UglifyJS-brunch |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Multi pages build with common bundle with manual configuration |
with manual configuration | yes | with manual configuration | with bundle arithmetic | no | no |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Multiple bundles yes |
yes | with manual configuration | with manual configuration | yes | no | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Node.js built-in libs yes |
yes | no | yes | yes | node-resolve-plugin | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Other Node.js stuff process, __dir/filename, global |
process, __dir/filename, global | - | process, __dir/filename, global | process, __dir/filename, global for cjs | global ( commonjs-plugin ) | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Plugins yes |
yes | yes | yes | yes | yes | yes |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Preprocessing loaders, transforms |
loaders, transforms | loaders | transforms | plugin translate | plugin transforms | compilers, optimizers |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Replacement for browser
|
web_modules
,
.web.js
, package.json field, alias config option |
alias option | package.json field, alias option | package.json, alias option | no | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Requirable files file system |
file system | web | file system | through plugins | file system or through plugins | file system |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Runtime overhead 243B + 20B per module + 4B per dependency |
243B + 20B per module + 4B per dependency | 14.7kB + 0B per module + (3B + X) per dependency | 415B + 25B per module + (6B + 2X) per dependency | 5.5kB for self-executing bundles, 38kB for full loader and polyfill, 0 plain modules, 293B CJS, 139B ES2015 System.register before gzip | none for ES2015 modules (other formats may have) | |
Feature webpack/webpack jrburke/requirejs substack/node-browserify jspm/jspm-cli rollup/rollup brunch/brunch Watch mode yes |
yes | not required | watchify | not needed in dev | rollup-watch | yes |
♦ in production mode (opposite in development mode)
X is the length of the path string
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.
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.
webpack should always be written in lower-case letters, even at the beginning of a sentence.
The webpack logo should be placed on a white background with enough space around it like this:
Just double the size of the inner dark blue cube to get an idea how much space the logo should have.
For dark backgrounds, you can use the negative version of the logo:
Please use the icon + text whenever possible.
The icon is designed to be used in layout-constrained areas. As previously stated, please prefer icon + text.
Square-sized icon for bigger areas (like avatars or profile pictures):
Square-sized icon for smaller areas (like favicons):
For those of you following our guidelines and have gotten this far, we've made a special smaller size image used especially for custom emoji (like in a slack or gitter channel ;))
We use the beautiful Geomanist Medium font from the extremely talented folks at the Atipo Foundry who provide the entire font family at a 'pay what you want' model.
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 |
---|---|---|---|
Color Name HEX Code RGB Code Sample Malibu: HEX |
HEX
#8dd6f9 |
rgb: 141, 214, 249 |
|
Color Name HEX Code RGB Code Sample Denim: HEX |
HEX
#1d78c1 |
rgb: 29, 120, 193 |
|
Color Name HEX Code RGB Code Sample Fiord: HEX |
HEX
#465E69 |
rgb: 70, 94, 105 |
|
Color Name HEX Code RGB Code Sample Outer Space: HEX |
HEX
#2B3A42 |
rgb: 43, 58, 66 |
|
Color Name HEX Code RGB Code Sample White: HEX |
HEX
#ffffff |
rgb: 255, 255, 255 |
|
Color Name HEX Code RGB Code Sample Concrete: HEX |
HEX
#f2f2f2 |
rgb: 242, 242, 242 |
|
Color Name HEX Code RGB Code Sample Alto: HEX |
HEX
#dedede |
rgb: 222, 222, 222 |
|
Color Name HEX Code RGB Code Sample Dusty Gray: HEX |
HEX
#999999 |
rgb: 153, 153, 153 |
|
Color Name HEX Code RGB Code Sample Dove Gray: HEX |
HEX
#666666 |
rgb: 102, 102, 102 |
|
Color Name HEX Code RGB Code Sample Emperor: HEX |
HEX
#535353 |
rgb: 83, 83, 83 |
|
Color Name HEX Code RGB Code Sample Mine Shaft: HEX |
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.
This index lists common terms used throughout the webpack ecosystem.
modules
while an application is running without a full page reload.require()
or "load" them. Similar to a 'task-runner'.resolve.modules
.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.
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.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.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.webpack is MIT licensed.
The webpack logo and icon are under a different license which can be found here.
The content on https://webpack.js.org/ is available under Creative Commons BY 4.0 license meaning attribution is required should you use the content elsewhere.
The code samples use CC0 1.0 Universal (CC0 1.0) (Public Domain) and you are free to use them as you like.