Skip to content

Commit 9cd0cac

Browse files
committed
Merge branch 'master' into next
2 parents 302289c + ce74935 commit 9cd0cac

21 files changed

Lines changed: 208 additions & 22 deletions

File tree

lib/Module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class Module extends DependenciesBlock {
223223
if(sortChunks)
224224
this._ensureChunksSorted();
225225
this.reasons.sort((a, b) => byId(a.module, b.module));
226+
if(Array.isArray(this.usedExports)) {
227+
this.usedExports.sort();
228+
}
226229
}
227230

228231
unbuild() {

lib/SourceMapDevToolPlugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"use strict";
66

77
const path = require("path");
8+
const crypto = require("crypto");
89
const RequestShortener = require("./RequestShortener");
910
const ConcatSource = require("webpack-sources").ConcatSource;
1011
const RawSource = require("webpack-sources").RawSource;
@@ -145,7 +146,10 @@ class SourceMapDevToolPlugin {
145146
query,
146147
basename: basename(filename)
147148
});
148-
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
149+
let sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
150+
if(sourceMapUrl.indexOf("[contenthash]") !== -1) {
151+
sourceMapUrl = sourceMapUrl.replace(/\[contenthash\]/g, crypto.createHash("md5").update(source).digest("hex"));
152+
}
149153
if(currentSourceMappingURLComment !== false) {
150154
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
151155
}

lib/UmdMainTemplatePlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class UmdMainTemplatePlugin {
7272
let expr;
7373
let request = m.request;
7474
if(typeof request === "object") request = request[type];
75+
if(typeof request === "undefined") throw new Error("Missing external configuration for type:" + type);
7576
if(Array.isArray(request)) {
7677
expr = `require(${JSON.stringify(request[0])})${accessorToObjectAccess(request.slice(1))}`;
7778
} else

lib/optimize/CommonsChunkPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ Take a look at the "name"/"names" or async/children option.`);
340340
moveExtractedChunkBlocksToTargetChunk(chunks, targetChunk) {
341341
for(let chunk of chunks) {
342342
for(let block of chunk.blocks) {
343-
block.chunks.unshift(targetChunk);
343+
if(block.chunks.indexOf(targetChunk) === -1) {
344+
block.chunks.unshift(targetChunk);
345+
}
344346
targetChunk.addBlock(block);
345347
}
346348
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"script-loader": "~0.7.0",
6262
"should": "^11.1.1",
6363
"simple-git": "^1.65.0",
64-
"sinon": "^1.17.7",
64+
"sinon": "^2.3.2",
6565
"style-loader": "~0.13.0",
6666
"url-loader": "~0.5.0",
6767
"val-loader": "~0.5.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "c";
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require("should");
2+
const sinon = require("sinon");
3+
const chunkLoadingSpy = sinon.spy(__webpack_require__, 'e');
4+
5+
it("should not have duplicate chunks in blocks", function(done) {
6+
// This split point should contain: a
7+
require.ensure([], function(require) {
8+
require("./a").should.be.eql("a");
9+
}, 'a');
10+
11+
// This split point should contain: a and b - we use CommonsChunksPlugin to
12+
// have it only contain b and make chunk a be an async dependency.
13+
require.ensure([], function(require) {
14+
require("./a").should.be.eql("a");
15+
require("./b").should.be.eql("b");
16+
}, 'a+b');
17+
18+
// This split point should contain: a, b and c - we use CommonsChunksPlugin to
19+
// have it only contain c and make chunks a and a+b be async dependencies.
20+
require.ensure([], function(require) {
21+
require("./a").should.be.eql("a");
22+
require("./b").should.be.eql("b");
23+
require("./c").should.be.eql("c");
24+
}, 'a+b+c');
25+
26+
// Each of the require.ensures above should end up resolving chunks:
27+
// - a
28+
// - a, a+b
29+
// - a, a+b, a+b+c
30+
chunkLoadingSpy.callCount.should.be.eql(6);
31+
chunkLoadingSpy.args.should.be.eql([[0], [0], [1], [0], [1], [2]]);
32+
done();
33+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var webpack = require("../../../../");
2+
3+
module.exports = {
4+
plugins: [
5+
new webpack.optimize.CommonsChunkPlugin({
6+
chunks: ["a+b", "a+b+c"],
7+
async: "a+b",
8+
}),
9+
new webpack.optimize.CommonsChunkPlugin({
10+
chunks: ["a", "a+b"],
11+
async: "a",
12+
}),
13+
]
14+
};

0 commit comments

Comments
 (0)