Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #7921 from webpack/bugfix/contenhash-id
chunk ids contribute to contenthash for javascript
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1 @@ | ||
module.exports = "chunk"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,5 @@ | ||
it("should compile and run the test", function () {}); | ||
|
||
if(Math.random() < -1) { | ||
import(/* webpackChunkName: "chunk" */ "./chunk"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,32 @@ | ||
var fs = require("fs"); | ||
|
||
var findFile = function(files, regex) { | ||
return files.find(function(file) { | ||
if (regex.test(file)) { | ||
return true; | ||
} | ||
}); | ||
}; | ||
|
||
const allFilenameHashes = new Set(); | ||
const allChunkHashes = new Set(); | ||
|
||
module.exports = { | ||
findBundle: function(i, options) { | ||
var files = fs.readdirSync(options.output.path); | ||
|
||
const filename = findFile(files, new RegExp(`^bundle${i}`)); | ||
const filenameHash = /\.([a-f0-9]+)\.js$/.exec(filename)[1]; | ||
allFilenameHashes.add(filenameHash); | ||
|
||
const chunk = findFile(files, new RegExp(`^chunk${i}`)); | ||
const chunkHash = /\.([a-f0-9]+)\.js$/.exec(chunk)[1]; | ||
allChunkHashes.add(chunkHash); | ||
|
||
return "./" + filename; | ||
}, | ||
afterExecute: () => { | ||
expect(allFilenameHashes.size).toBe(2); | ||
expect(allChunkHashes.size).toBe(2); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,26 @@ | ||
module.exports = [ | ||
{ | ||
mode: "production", | ||
name: "normal-ids", | ||
output: { | ||
filename: "bundle0.[contenthash:6].js", | ||
chunkFilename: "chunk0.[contenthash:6].js" | ||
}, | ||
optimization: { | ||
chunkIds: "size", | ||
moduleIds: "named" | ||
} | ||
}, | ||
{ | ||
mode: "production", | ||
name: "normal-ids", | ||
output: { | ||
filename: "bundle1.[contenthash:6].js", | ||
chunkFilename: "chunk1.[contenthash:6].js" | ||
}, | ||
optimization: { | ||
chunkIds: "named", | ||
moduleIds: "named" | ||
} | ||
} | ||
]; |