2012-10-26 06:01:57 +08:00
|
|
|
[](http://webpack.github.com)
|
2012-03-10 20:11:23 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
[documentation](https://github.com/webpack/docs/wiki)
|
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-01-31 01:49:25 +08:00
|
|
|
webpack is a bundler for modules. The main purpose is to bundle javascript files for useage in browser.
|
2012-04-08 03:36:55 +08:00
|
|
|
|
2012-03-10 20:11:23 +08:00
|
|
|
**TL;DR**
|
|
|
|
|
2013-02-26 21:05:09 +08:00
|
|
|
* bundles [CommonJs](http://www.commonjs.org/specs/modules/1.0/), [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) and/or [Labeled Modules](https://github.com/labeledmodules/labeled-modules-spec/wiki) 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
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
Check the [documentation](https://github.com/webpack/docs/wiki) if you want to know more...
|
2012-03-10 20:11:23 +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
|
|
|
|
|
|
|
# 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
|
|
|
|
* interfaces
|
|
|
|
* CLI with arguments
|
|
|
|
* CLI with config file, arguments still possible
|
|
|
|
* usable as library from node.js
|
|
|
|
* usable as grunt plugin
|
|
|
|
* browser replacements
|
|
|
|
* comes with browser replacements for some node.js modules
|
|
|
|
* 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");
|
2013-02-26 21:05:09 +08:00
|
|
|
require: "./labeled";
|
2013-01-31 01:49:25 +08:00
|
|
|
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
|
|
|
|
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...
|
|
|
|
|
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-03-11 17:06:33 +08:00
|
|
|
[](https://david-dm.org/webpack/webpack)
|