Skip to content

Commit 0e60343

Browse files
authored
Merge pull request webpack#7921 from webpack/bugfix/contenhash-id
chunk ids contribute to contenthash for javascript
2 parents a02bf99 + c253b4b commit 0e60343

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

lib/JavascriptModulesPlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class JavascriptModulesPlugin {
135135
const template = chunk.hasRuntime()
136136
? compilation.mainTemplate
137137
: compilation.chunkTemplate;
138+
hash.update(`${chunk.id} `);
139+
hash.update(chunk.ids ? chunk.ids.join(",") : "");
138140
template.updateHashForChunk(hash, chunk);
139141
for (const m of chunk.modulesIterable) {
140142
if (typeof m.source === "function") {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "chunk";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
it("should compile and run the test", function () {});
2+
3+
if(Math.random() < -1) {
4+
import(/* webpackChunkName: "chunk" */ "./chunk");
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var fs = require("fs");
2+
3+
var findFile = function(files, regex) {
4+
return files.find(function(file) {
5+
if (regex.test(file)) {
6+
return true;
7+
}
8+
});
9+
};
10+
11+
const allFilenameHashes = new Set();
12+
const allChunkHashes = new Set();
13+
14+
module.exports = {
15+
findBundle: function(i, options) {
16+
var files = fs.readdirSync(options.output.path);
17+
18+
const filename = findFile(files, new RegExp(`^bundle${i}`));
19+
const filenameHash = /\.([a-f0-9]+)\.js$/.exec(filename)[1];
20+
allFilenameHashes.add(filenameHash);
21+
22+
const chunk = findFile(files, new RegExp(`^chunk${i}`));
23+
const chunkHash = /\.([a-f0-9]+)\.js$/.exec(chunk)[1];
24+
allChunkHashes.add(chunkHash);
25+
26+
return "./" + filename;
27+
},
28+
afterExecute: () => {
29+
expect(allFilenameHashes.size).toBe(2);
30+
expect(allChunkHashes.size).toBe(2);
31+
}
32+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = [
2+
{
3+
mode: "production",
4+
name: "normal-ids",
5+
output: {
6+
filename: "bundle0.[contenthash:6].js",
7+
chunkFilename: "chunk0.[contenthash:6].js"
8+
},
9+
optimization: {
10+
chunkIds: "size",
11+
moduleIds: "named"
12+
}
13+
},
14+
{
15+
mode: "production",
16+
name: "normal-ids",
17+
output: {
18+
filename: "bundle1.[contenthash:6].js",
19+
chunkFilename: "chunk1.[contenthash:6].js"
20+
},
21+
optimization: {
22+
chunkIds: "named",
23+
moduleIds: "named"
24+
}
25+
}
26+
];

0 commit comments

Comments
 (0)