Skip to content

Commit

Permalink
Merge pull request #7601 from webpack/bugfix/hash-entry-chunks
Browse files Browse the repository at this point in the history
fixes #7577
  • Loading branch information
sokra committed Jun 26, 2018
2 parents aab3554 + e38e076 commit 9dacf86
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 83 deletions.
31 changes: 24 additions & 7 deletions lib/web/JsonpChunkTemplatePlugin.js
Expand Up @@ -6,7 +6,23 @@

const { ConcatSource } = require("webpack-sources");

/** @typedef {import("../ChunkTemplate")} ChunkTemplate */

const getEntryInfo = chunk => {
return [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
};

class JsonpChunkTemplatePlugin {
/**
* @param {ChunkTemplate} chunkTemplate the chunk template
* @returns {void}
*/
apply(chunkTemplate) {
chunkTemplate.hooks.render.tap(
"JsonpChunkTemplatePlugin",
Expand All @@ -23,13 +39,7 @@ class JsonpChunkTemplatePlugin {
)}] || []).push([${JSON.stringify(chunk.ids)},`
);
source.add(modules);
const entries = [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
const entries = getEntryInfo(chunk);
if (entries.length > 0) {
source.add(`,${JSON.stringify(entries)}`);
} else if (prefetchChunks && prefetchChunks.length) {
Expand All @@ -49,6 +59,13 @@ class JsonpChunkTemplatePlugin {
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
});
chunkTemplate.hooks.hashForChunk.tap(
"JsonpChunkTemplatePlugin",
(hash, chunk) => {
hash.update(JSON.stringify(getEntryInfo(chunk)));
hash.update(JSON.stringify(chunk.getChildIdsByOrders().prefetch) || "");
}
);
}
}
module.exports = JsonpChunkTemplatePlugin;
192 changes: 116 additions & 76 deletions test/__snapshots__/StatsTestCases.test.js.snap

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/statsCases/issue-7577/a.js
@@ -0,0 +1 @@
console.log("a");
1 change: 1 addition & 0 deletions test/statsCases/issue-7577/b.js
@@ -0,0 +1 @@
import "vendor";
2 changes: 2 additions & 0 deletions test/statsCases/issue-7577/c.js
@@ -0,0 +1,2 @@
console.log("c");
import(/* webpackPrefetch: true */ "./b");
1 change: 1 addition & 0 deletions test/statsCases/issue-7577/node_modules/vendor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions test/statsCases/issue-7577/webpack.config.js
@@ -0,0 +1,45 @@
const base = {
mode: "production",
optimization: {
runtimeChunk: true,
namedChunks: true,
splitChunks: {
minSize: 0,
chunks: "all",
cacheGroups: {
all: {
priority: -30
}
}
}
}
};
module.exports = [
Object.assign(
{
entry: "./a.js",
output: {
filename: "a-[name]-[chunkhash].js"
}
},
base
),
Object.assign(
{
entry: "./b.js",
output: {
filename: "b-[name]-[chunkhash].js"
}
},
base
),
Object.assign(
{
entry: "./c.js",
output: {
filename: "c-[name]-[chunkhash].js"
}
},
base
)
];

0 comments on commit 9dacf86

Please sign in to comment.