Skip to content

Commit 9c26ffe

Browse files
committed
Merge branch 'master' into webpack-2
Conflicts: lib/Stats.js
2 parents 3092982 + 0bc887a commit 9c26ffe

12 files changed

Lines changed: 65 additions & 47 deletions

‎README.md‎

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ files for usage in a browser, yet it is also capable of transforming, bundling,
1111
or packaging just about any resource or asset.
1212

1313

14-
**TL;DR**
14+
**TL; DR**
1515

1616
* Bundles both [CommonJs](http://www.commonjs.org/specs/modules/1.0/) and [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules (even combined).
1717
* Can create a single bundle or multiple chunks that are asynchronously loaded at runtime (to reduce initial loading time).
@@ -135,63 +135,61 @@ friendly** by using hashes.
135135

136136
[Optimization documentation](http://webpack.github.io/docs/optimization.html)
137137

138+
webpack optimizes in several ways. It also makes your chunks **cache-friendly** by using hashes.
138139

139140
# A small example of what's possible
140141

141142
``` javascript
142-
// webpack is a module bundler
143+
// webpack is a module bundler.
143144
// This means webpack takes modules with dependencies
144-
// and emits static assets representing those modules.
145+
// and emits static assets representing those modules.
145146

146-
// dependencies can be written in CommonJs
147+
// Dependencies can be written in CommonJs
147148
var commonjs = require("./commonjs");
148149
// or in AMD
149-
define(["amd-module", "../file"], function(amdModule, file) {
150-
// while previous constructs are sync
150+
define(["amd-module", "../file"], function (amdModule, file) {
151+
// while previous constructs are sync,
151152
// this is async
152-
require(["big-module/big/file"], function(big) {
153-
// for async dependencies webpack splits
154-
// your application into multiple "chunks".
153+
require(["big-module/big/file"], function (big) {
154+
// For async dependencies, webpack splits
155+
// your application into multiple "chunks."
155156
// This part of your application is
156-
// loaded on demand (Code Splitting)
157+
// loaded on demand (code-splitting).
157158
var stuff = require("../my/stuff");
158-
// "../my/stuff" is also loaded on demand
159+
// "../my/stuff" is also loaded on-demand
159160
// because it's in the callback function
160-
// of the AMD require
161+
// of the AMD require.
161162
});
162163
});
163164

164165

165166
require("coffee!./cup.coffee");
166-
// "Loaders" can be used to preprocess files.
167+
// "Loaders" are used to preprocess files.
167168
// They can be prefixed in the require call
168-
// or configured in the configuration.
169+
// or configured in the configuration.
169170
require("./cup");
170171
// This does the same when you add ".coffee" to the extensions
171-
// and configure the "coffee" loader for /\.coffee$/
172-
173-
174-
function loadTemplate(name) {
172+
// and configure the "coffee" loader for /\.coffee$/
173+
174+
function loadTemplate (name) {
175175
return require("./templates/" + name + ".jade");
176-
// many expressions are supported in require calls
177-
// a clever parser extracts information and concludes
178-
// that everything in "./templates" that matches
179-
// /\.jade$/ should be included in the bundle, as it
180-
// can be required.
176+
// Many expressions are supported in require calls.
177+
// A clever parser extracts information and concludes
178+
// that everything in "./templates" that matches
179+
// /\.jade$/ should be included in the bundle, as it
180+
// can be required.
181181
}
182-
183-
184-
// ... and you can combine everything
185-
function loadTemplateAsync(name, callback) {
182+
183+
184+
// ...and you can combine everything.
185+
function loadTemplateAsync (name, callback) {
186186
require(["bundle?lazy!./templates/" + name + ".jade"],
187-
function(templateBundle) {
188-
templateBundle(callback);
187+
function (templateBundle) {
188+
templateBundle(callback);
189189
});
190190
}
191191
```
192192

193-
194-
195193
## Documentation
196194

197195
[documentation](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=documentation)
@@ -204,7 +202,7 @@ function loadTemplateAsync(name, callback) {
204202

205203
## Tests
206204

207-
You can run the node tests with `npm test`. [![build status (linux)](https://secure.travis-ci.org/webpack/webpack.png)](http://travis-ci.org/webpack/webpack) [![Build status (windows)](https://ci.appveyor.com/api/projects/status/vatlasj366jiyuh6/branch/master)](https://ci.appveyor.com/project/sokra/webpack/branch/master)
205+
You can run the Node tests with `npm test`. [![build status (linux)](https://secure.travis-ci.org/webpack/webpack.png)](http://travis-ci.org/webpack/webpack) [![Build status (windows)](https://ci.appveyor.com/api/projects/status/vatlasj366jiyuh6/branch/master)](https://ci.appveyor.com/project/sokra/webpack/branch/master)
208206

209207
You can run the browser tests:
210208

@@ -213,8 +211,7 @@ cd test/browsertests
213211
node build
214212
```
215213

216-
and open `tests.html` in browser.
217-
214+
and open `tests.html` in the browser.
218215

219216
## Contribution
220217

@@ -233,19 +230,17 @@ You are also welcome to correct any spelling mistakes or any language issues.
233230

234231
If you want to discuss something or just need help, [here is our gitter.im room](https://gitter.im/webpack/webpack).
235232

236-
237233
## License
238234

239235
Copyright (c) 2012-2015 Tobias Koppers
240236

241237
MIT (http://www.opensource.org/licenses/mit-license.php)
242238

243-
244239
## Sponsor
245240

246-
This is a freetime project. My time investment fluctuates randomly. If you use webpack for a serious task you may want me to invest more time. Or if you make some good revenue you can give some money back. Keep in mind that this project may increase your income. It makes development and applications faster and reduces the required bandwidth.
241+
This is a free-time project. The time I invest in it fluctuates. If you use webpack for a serious task, and you'd like me to invest more time on it, please donate. This project increases your income/productivity too. It makes development and applications faster and it reduces the required bandwidth.
247242

248-
I'm very thankful for every dollar. If you leave your username or email I may show my thanks by giving you extra support.
243+
I'm very thankful for every dollar. If you leave your username or email, I may show my thanks by giving you extra support.
249244

250245
[![Donate to sokra](http://img.shields.io/donate/sokra.png)](http://sokra.github.io/)
251246

‎lib/Compilation.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ Compilation.prototype.seal = function seal(callback) {
503503
return callback(err);
504504
}
505505

506+
this.applyPlugins("after-optimize-tree", this.chunks, this.modules);
507+
506508
var shouldRecord = this.applyPluginsBailResult("should-record") !== false;
507509

508510
this.applyPlugins("revive-modules", this.modules, this.records);

‎lib/JsonpMainTemplatePlugin.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
3333
var filename = this.outputOptions.filename || "bundle.js";
3434
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
3535
var chunkMaps = chunk.getChunkMaps();
36+
var crossOriginLoading = this.outputOptions.crossOriginLoading;
3637
return this.asString([
3738
"// \"0\" is the signal for \"already loaded\"",
3839
"if(installedChunks[chunkId] === 0)",
@@ -50,6 +51,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
5051
"script.type = 'text/javascript';",
5152
"script.charset = 'utf-8';",
5253
"script.async = true;",
54+
crossOriginLoading ? "script.crossOrigin = '" + crossOriginLoading + "';" : "",
5355
"script.src = " + this.requireFn + ".p + " +
5456
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
5557
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",

‎lib/MainTemplate.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ function MainTemplate(outputOptions) {
8383
buf.push("// expose the module cache");
8484
buf.push(this.requireFn + ".c = installedModules;");
8585

86-
var publicPath = this.outputOptions.publicPath || "";
87-
publicPath = this.applyPluginsWaterfall("asset-path", publicPath, {
86+
var publicPath = this.getPublicPath({
8887
hash: hash
8988
});
9089
buf.push("");
@@ -145,6 +144,10 @@ MainTemplate.prototype.entryPointInChildren = function(chunk) {
145144
}(chunk, []));
146145
};
147146

147+
MainTemplate.prototype.getPublicPath = function(options) {
148+
return this.applyPluginsWaterfall("asset-path", this.outputOptions.publicPath || "", options);
149+
};
150+
148151
MainTemplate.prototype.updateHash = function(hash) {
149152
hash.update("maintemplate");
150153
hash.update("3");

‎lib/SourceMapDevToolPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
3333
var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
3434
var requestShortener = new RequestShortener(compiler.context);
3535
var options = this.options;
36-
options.test = options.test || /\.js($|\?)/i;
36+
options.test = options.test || /\.(js|css)($|\?)/i;
3737
compiler.plugin("compilation", function(compilation) {
3838
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
3939
compilation.plugin("after-optimize-chunk-assets", function(chunks) {

‎lib/Stats.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
3737
var showChildren = d(options.children, true);
3838
var showSource = d(options.source, !forToString);
3939
var showErrorDetails = d(options.errorDetails, !forToString);
40+
var showPublicPath = d(options.publicPath, !forToString);
4041
var excludeModules = [].concat(d(options.exclude, [])).map(function(str) {
4142
if(typeof str !== "string") return str;
4243
return new RegExp("[\\\\/]" + str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "([\\\\/]|$|!|\\?)");
@@ -109,7 +110,12 @@ Stats.prototype.toJson = function toJson(options, forToString) {
109110
obj.time = this.endTime - this.startTime;
110111
}
111112
if(compilation.needAdditionalPass) {
112-
obj.needAdditionalPass = true
113+
obj.needAdditionalPass = true;
114+
}
115+
if(showPublicPath) {
116+
obj.publicPath = this.compilation.mainTemplate.getPublicPath({
117+
hash: this.compilation.hash
118+
});
113119
}
114120
if(showAssets) {
115121
var assetsByFile = {};
@@ -368,6 +374,11 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
368374
normal("ms");
369375
newline();
370376
}
377+
if(obj.publicPath) {
378+
normal("PublicPath: ")
379+
bold(obj.publicPath);
380+
newline();
381+
}
371382
if(obj.assets && obj.assets.length > 0) {
372383
var t = [["Asset", "Size", "Chunks", "", "Chunk Names"]]
373384
obj.assets.forEach(function(asset) {

‎lib/WebpackOptionsDefaulter.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function WebpackOptionsDefaulter() {
3434
this.set("output.sourceMapFilename", "[file].map[query]");
3535
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
3636
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
37+
this.set("output.crossOriginLoading", false);
3738
this.set("output.hashFunction", "md5");
3839
this.set("output.hashDigest", "hex");
3940
this.set("output.hashDigestLength", 20);

‎lib/optimize/DedupePlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DedupePlugin.prototype.apply = function(compiler) {
3333
}
3434
});
3535
});
36-
compilation.plugin("after-optimize-chunks", function(chunks) {
36+
compilation.plugin("after-optimize-tree", function(chunks) {
3737
var entryChunks = chunks.filter(function(c) { return c.entry; });
3838
entryChunks.forEach(function(chunk) { // for each entry chunk
3939
var hasDeduplicatedModules = false;

‎lib/optimize/MinChunkSizePlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ MinChunkSizePlugin.prototype.apply = function(compiler) {
2929
return pair[0].size(equalOptions) < minChunkSize || pair[1].size(equalOptions) < minChunkSize;
3030
});
3131

32-
if(combinations.length === 0) return;
33-
3432
combinations.forEach(function(pair) {
3533
var a = pair[0].size(options);
3634
var b = pair[1].size(options);
@@ -41,6 +39,8 @@ MinChunkSizePlugin.prototype.apply = function(compiler) {
4139
combinations = combinations.filter(function(pair) {
4240
return pair[1] !== false;
4341
});
42+
43+
if(combinations.length === 0) return;
4444

4545
combinations.sort(function(a,b) {
4646
var diff = b[0] - a[0];

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "1.8.4",
3+
"version": "1.8.7",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {
@@ -63,6 +63,7 @@
6363
"bin": "./bin/webpack.js",
6464
"scripts": {
6565
"test": "mocha --reporter spec",
66-
"cover": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec"
66+
"cover": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec",
67+
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
6768
}
6869
}

0 commit comments

Comments
 (0)