2014-01-14 16:57:26 +08:00
[](http://webpack.github.io)
2012-03-10 20:11:23 +08:00
2014-01-08 18:23:58 +08:00
[](http://badge.fury.io/js/webpack)
2013-07-31 16:50:43 +08:00
2014-01-14 22:40:37 +08:00
[documentation ](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=top )
2012-04-03 22:26:08 +08:00
2013-01-31 01:49:25 +08:00
# Introduction
2012-03-10 20:11:23 +08:00
2013-05-31 18:22:40 +08:00
webpack is a bundler for modules. The main purpose is to bundle javascript files for usage in browser.
2012-04-08 03:36:55 +08:00
2012-03-10 20:11:23 +08:00
**TL;DR**
2014-01-14 16:42:48 +08:00
* bundles [CommonJs ](http://www.commonjs.org/specs/modules/1.0/ ) and [AMD ](https://github.com/amdjs/amdjs-api/wiki/AMD ) modules. (even combined)
2013-01-31 01:49:25 +08:00
* can create a single bundle or a bunch of chunks loaded on demand, to reduce initial loading time.
* dependencies are resolved while compiling, this makes the runtime very small
* loader can preprocess files while compiling, i. e. coffee-script to javascript
2012-03-20 02:59:38 +08:00
2014-01-14 22:40:37 +08:00
Check the [documentation ](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=trdr ) if you want to know more...
2012-03-10 20:11:23 +08:00
2013-12-05 23:28:50 +08:00
2012-05-22 01:31:13 +08:00
# Examples
2012-04-08 18:53:54 +08:00
2013-03-26 23:54:41 +08:00
Take a look at the [`examples` ](https://github.com/webpack/webpack/tree/master/examples ) folder.
2013-01-31 01:49:25 +08:00
2013-12-05 23:28:50 +08:00
2013-01-31 01:49:25 +08:00
# Features
* loaders are chainable
* loaders run in node.js and can do a bunch of stuff
* option to name your file with a hash of the content
* watch mode
2013-03-26 23:54:41 +08:00
* SourceUrl and SourceMap support
2013-01-31 01:49:25 +08:00
* plugin system, extend webpack or build a complete different compiler
2014-01-14 22:40:37 +08:00
* i. e. [component ](https://github.com/webpack/component-webpack-plugin ), [rewire ](https://github.com/jhnns/rewire-webpack ) and [more... ](http://webpack.github.io/docs/webpack-plugins.html?utm_source=github&utm_medium=readme&utm_campaign=features )
* [interfaces ](http://webpack.github.io/docs/webpack-usage.html?utm_source=github&utm_medium=readme&utm_campaign=features )
* CLI with [arguments ](http://webpack.github.io/docs/webpack-detailed-usage.html?utm_source=github&utm_medium=readme&utm_campaign=features )
* CLI with [config file ](http://webpack.github.io/docs/webpack-options.html?utm_source=github&utm_medium=readme&utm_campaign=features ), [arguments ](http://webpack.github.io/docs/webpack-detailed-usage.html?utm_source=github&utm_medium=readme&utm_campaign=features ) are still possible
2013-01-31 01:49:25 +08:00
* usable as library from node.js
2013-05-31 19:46:21 +08:00
* usable as [grunt plugin ](https://github.com/webpack/grunt-webpack )
2013-01-31 01:49:25 +08:00
* browser replacements
* comes with browser replacements for some node.js modules
2014-01-14 22:40:37 +08:00
* [Hot Module Replacement ](http://webpack.github.io/docs/hot-code-replacement.html?utm_source=github&utm_medium=readme&utm_campaign=features )
2013-06-19 19:49:57 +08:00
* install updates without full page refresh
2013-01-31 01:49:25 +08:00
* see also
* [webpack-dev-middleware ](https://github.com/webpack/webpack-dev-middleware )
* [webpack-dev-server ](https://github.com/webpack/webpack-dev-server )
* [enhanced-resolve ](https://github.com/webpack/enhanced-resolve ) and
* [enhanced-require ](https://github.com/webpack/enhanced-require )
## A small example what's possible
2012-03-27 10:23:11 +08:00
``` javascript
2013-01-31 01:49:25 +08:00
var commonjs = require("./commonjs");
define(["amd-module", "./file"], function(amdModule, file) {
require(["big-module/big/file"], function(big) {
// AMD require acts as split point
// and "big-module/big/file" is only downloaded when requested
var stuff = require("../my/stuff");
// dependencies automatically goes in chunk too
});
2012-03-27 10:23:11 +08:00
});
2012-03-10 20:11:23 +08:00
2013-01-31 01:49:25 +08:00
require("coffee!./cup.coffee");
// The loader syntax allows to proprocess files
// for common stuff you can bind RegExps to loaders
// if you also add ".coffee" to the default extensions
// you can write:
require("./cup");
function loadTemplate(name) {
return require("./templates/" + name ".jade");
// dynamic requires are supported
// while compiling we figure out what can be requested
// here everything in "./templates" that matches /^.*\.jade$/
// (can also be in subdirectories)
2012-05-12 22:43:37 +08:00
}
2012-03-12 05:16:24 +08:00
2013-01-31 01:49:25 +08:00
require("imports?_=underscore!../loaders/my-ejs-loader!./template.html");
// you can chain loaders
// you can configure loaders with query parameters
// and loaders resolve similar to modules
2012-10-26 16:48:55 +08:00
2013-01-31 01:49:25 +08:00
// ...you can combine everything
function loadTemplateAsync(name, callback) {
require(["bundle?lazy!./templates/" + name + ".jade"], function(templateBundle) {
templateBundle(callback);
});
2012-05-12 22:43:37 +08:00
}
```
2012-03-10 20:11:23 +08:00
2012-03-27 06:34:38 +08:00
2013-05-31 19:46:21 +08:00
## Documentation
2014-01-14 22:40:37 +08:00
[documentation ](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=documentation )
2013-05-31 19:46:21 +08:00
2012-03-10 20:11:23 +08:00
## Tests
2012-10-26 06:01:57 +08:00
You can run the unit tests with `npm test` . [](http://travis-ci.org/webpack/webpack)
2012-03-10 20:11:23 +08:00
You can run the browser tests:
```
cd test/browsertests
node build
```
2012-10-29 05:56:55 +08:00
and open `tests.html` in browser.
2012-03-10 20:11:23 +08:00
2012-10-26 06:01:57 +08:00
2012-03-10 20:11:23 +08:00
## Contribution
You are welcome to contribute by writing issues or pull requests.
2012-05-08 05:46:59 +08:00
It would be nice if you open source your own loaders or webmodules. :)
2012-03-10 20:11:23 +08:00
2012-03-21 06:28:43 +08:00
You are also welcome to correct any spelling mistakes or any language issues, because my english is not perfect...
2013-12-16 06:30:25 +08:00
If you want to discus something or just need help, [here is a gitter.im room ](https://gitter.im/webpack/webpack ).
2012-10-26 06:01:57 +08:00
2012-03-10 20:11:23 +08:00
## License
2013-01-31 01:49:25 +08:00
Copyright (c) 2012-2013 Tobias Koppers
2012-05-25 06:17:02 +08:00
2012-05-12 23:02:20 +08:00
MIT (http://www.opensource.org/licenses/mit-license.php)
2012-10-26 06:01:57 +08:00
2013-01-31 01:49:25 +08:00
2012-05-12 23:02:20 +08:00
## Dependencies
* [esprima ](http://esprima.org/ )
2013-01-31 01:49:25 +08:00
* [enhanced-resolve ](https://github.com/webpack/enhanced-resolve )
2012-05-12 23:02:20 +08:00
* [uglify-js ](https://github.com/mishoo/UglifyJS )
2013-01-31 01:49:25 +08:00
* [mocha ](https://github.com/visionmedia/mocha )
* [should ](https://github.com/visionmedia/should.js )
* [optimist ](https://github.com/substack/node-optimist )
* [async ](https://github.com/caolan/async )
* [mkdirp ](http://esprima.org/ )
2013-02-11 07:43:35 +08:00
* [clone ](https://github.com/pvorb/node-clone )
2013-05-31 19:46:21 +08:00
* [base64-encode ](https://github.com/ForbesLindesay/base64-encode )
2013-02-11 07:43:35 +08:00
2013-03-11 17:06:33 +08:00
[](https://david-dm.org/webpack/webpack)