File tree Expand file tree Collapse file tree
test/configCases/contenthash/salt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -393,6 +393,9 @@ ${referencingAssets
393393 let newHash = hooks . updateHash . call ( assetsContent , oldHash ) ;
394394 if ( ! newHash ) {
395395 const hash = createHash ( this . _hashFunction ) ;
396+ if ( compilation . outputOptions . hashSalt ) {
397+ hash . update ( compilation . outputOptions . hashSalt ) ;
398+ }
396399 for ( const content of assetsContent ) {
397400 hash . update ( content ) ;
398401 }
Original file line number Diff line number Diff line change 1+ import img from "./img.jpg" ;
2+
3+ it ( "should compile" , ( ) => {
4+ expect ( typeof img ) . toBe ( "string" ) ;
5+ } ) ;
Original file line number Diff line number Diff line change 1+ const findOutputFiles = require ( "../../../helpers/findOutputFiles" ) ;
2+
3+ const allAssets = new Set ( ) ;
4+ const allBundles = new Set ( ) ;
5+
6+ module . exports = {
7+ findBundle : function ( i , options ) {
8+ const bundle = findOutputFiles ( options , new RegExp ( `^bundle${ i } ` ) ) [ 0 ] ;
9+ allBundles . add ( / \. ( [ ^ . ] + ) \. / . exec ( bundle ) [ 1 ] ) ;
10+
11+ const assets = findOutputFiles ( options , / ^ i m g / ) ;
12+ for ( const asset of assets ) {
13+ allAssets . add ( asset ) ;
14+ }
15+
16+ return `./${ bundle } ` ;
17+ } ,
18+ afterExecute : ( ) => {
19+ // Since there are exactly 2 unique values of output.hashSalt,
20+ // there should be exactly 2 unique output hashes for each file.
21+ expect ( allBundles . size ) . toBe ( 2 ) ;
22+ expect ( allAssets . size ) . toBe ( 2 ) ;
23+ }
24+ } ;
Original file line number Diff line number Diff line change 1+ /** @type {import("../../../../").Configuration[] } */
2+ module . exports = [
3+ {
4+ output : {
5+ filename : "bundle0.[contenthash].js" ,
6+ assetModuleFilename : "[name].[contenthash][ext]" ,
7+ hashSalt : "1"
8+ } ,
9+ module : {
10+ rules : [
11+ {
12+ test : / \. j p g $ / ,
13+ type : "asset/resource"
14+ }
15+ ]
16+ }
17+ } ,
18+ {
19+ output : {
20+ filename : "bundle1.[contenthash].js" ,
21+ assetModuleFilename : "[name].[contenthash][ext]" ,
22+ hashSalt : "1"
23+ } ,
24+ module : {
25+ rules : [
26+ {
27+ test : / \. j p g $ / ,
28+ type : "asset/resource"
29+ }
30+ ]
31+ }
32+ } ,
33+ {
34+ output : {
35+ filename : "bundle2.[contenthash].js" ,
36+ assetModuleFilename : "[name].[contenthash][ext]" ,
37+ hashSalt : "2"
38+ } ,
39+ module : {
40+ rules : [
41+ {
42+ test : / \. j p g $ / ,
43+ type : "asset/resource"
44+ }
45+ ]
46+ }
47+ }
48+ ] ;
You can’t perform that action at this time.
0 commit comments