Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RealContentHashPlugin to initialize hash instances with the value of `output.hashSalt`, if provided.
- Loading branch information
Build Service Account
authored and
Build Service Account
committed
Mar 8, 2023
1 parent
c98e9e0
commit cc0b9d8
Showing
5 changed files
with
80 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import img from "./img.jpg"; | ||
|
||
it("should compile", () => { | ||
expect(typeof img).toBe("string"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const findOutputFiles = require("../../../helpers/findOutputFiles"); | ||
|
||
const allAssets = new Set(); | ||
const allBundles = new Set(); | ||
|
||
module.exports = { | ||
findBundle: function(i, options) { | ||
const bundle = findOutputFiles(options, new RegExp(`^bundle${i}`))[0]; | ||
allBundles.add(/\.([^.]+)\./.exec(bundle)[1]); | ||
|
||
const assets = findOutputFiles(options, /^img/); | ||
for (const asset of assets) { | ||
allAssets.add(asset); | ||
} | ||
|
||
return `./${bundle}`; | ||
}, | ||
afterExecute: () => { | ||
// Since there are exactly 2 unique values of output.hashSalt, | ||
// there should be exactly 2 unique output hashes for each file. | ||
expect(allBundles.size).toBe(2); | ||
expect(allAssets.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** @type {import("../../../../").Configuration[]} */ | ||
module.exports = [ | ||
{ | ||
output: { | ||
filename: "bundle0.[contenthash].js", | ||
assetModuleFilename: "[name].[contenthash][ext]", | ||
hashSalt: "1" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jpg$/, | ||
type: "asset/resource" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
output: { | ||
filename: "bundle1.[contenthash].js", | ||
assetModuleFilename: "[name].[contenthash][ext]", | ||
hashSalt: "1" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jpg$/, | ||
type: "asset/resource" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
output: { | ||
filename: "bundle2.[contenthash].js", | ||
assetModuleFilename: "[name].[contenthash][ext]", | ||
hashSalt: "2" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jpg$/, | ||
type: "asset/resource" | ||
} | ||
] | ||
} | ||
} | ||
]; |