Skip to content

Commit b92af72

Browse files
committed
fixed webpack#158
1 parent b2c751f commit b92af72

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎lib/JsonpMainTemplate.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ JsonpMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
3838
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
3939
var chunkHashMap = {};
4040
(function addChunk(c) {
41-
if(chunkHashMap[c.id]) return;
41+
if(c.id in chunkHashMap) return;
4242
if(c.id > 0)
4343
chunkHashMap[c.id] = c.renderedHash;
44+
else
45+
chunkHashMap[c.id] = undefined;
4446
c.chunks.forEach(addChunk);
4547
}(chunk));
4648
return [
@@ -96,8 +98,8 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) {
9698
"}",
9799
"while(callbacks.length)",
98100
this.indent("callbacks.shift().call(null, " + this.requireFn + ");"),
99-
(chunk.ids.indexOf(0) < 0 ? [
100-
"if(0 in moreModules) {",
101+
(this.entryPointInChildren(chunk) ? [
102+
"if(moreModules[0]) {",
101103
this.indent([
102104
"installedModules[0] = 0;",
103105
this.requireFn + "(0);"

‎lib/MainTemplate.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ MainTemplate.prototype.renderCurrentHashCode = function(hash) {
160160
return JSON.stringify(hash);
161161
};
162162

163+
MainTemplate.prototype.entryPointInChildren = function(chunk) {
164+
return (function checkChildren(chunk, alreadyCheckedChunks) {
165+
return chunk.chunks.some(function(child) {
166+
if(alreadyCheckedChunks.indexOf(child) >= 0) return;
167+
alreadyCheckedChunks.push(child);
168+
return child.modules.some(function(module) {
169+
return (module.id === 0);
170+
}) || checkChildren(child, alreadyCheckedChunks);
171+
});
172+
}(chunk, []));
173+
};
174+
163175
MainTemplate.prototype.updateHash = function(hash) {
164176
hash.update("maintemplate");
165177
hash.update("2");

‎lib/optimize/CommonsChunkPlugin.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
2020
compilation.plugin("optimize-chunks", function(chunks) {
2121
var commonModulesCount = [];
2222
var commonModules = [];
23+
var commonChunk = this.addChunk(filenameTemplate);
2324
var usedChunks = chunks.filter(function(chunk) {
25+
if(chunk === commonChunk) return false;
2426
if(!chunk.entry) return false;
2527
if(!entryPoints) return true;
2628
return entryPoints.indexOf(chunk.name) >= 0;
@@ -36,7 +38,6 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
3638
}
3739
});
3840
});
39-
var commonChunk = this.addChunk(filenameTemplate);
4041
commonModulesCount.forEach(function(count, idx) {
4142
if(count >= (minCount || usedChunks.length)) {
4243
var module = commonModules[idx];

0 commit comments

Comments
 (0)