@@ -10,6 +10,10 @@ const NS = path.dirname(fs.realpathSync(__filename));
1010
1111const pluginName = 'mini-css-extract-plugin' ;
1212
13+ const REGEXP_CHUNKHASH = / \[ c h u n k h a s h (?: : ( \d + ) ) ? \] / i;
14+ const REGEXP_CONTENTHASH = / \[ c o n t e n t h a s h (?: : ( \d + ) ) ? \] / i;
15+ const REGEXP_NAME = / \[ n a m e \] / i;
16+
1317class CssDependency extends webpack . Dependency {
1418 constructor ( { identifier, content, media, sourceMap } , context , identifierIndex ) {
1519 super ( ) ;
@@ -61,6 +65,16 @@ class CssModule extends webpack.Module {
6165 return resource ;
6266 }
6367
68+ updateCacheModule ( module ) {
69+ this . content = module . content ;
70+ this . media = module . media ;
71+ this . sourceMap = module . sourceMap ;
72+ }
73+
74+ needRebuild ( ) {
75+ return true ;
76+ }
77+
6478 build ( options , compilation , resolver , fileSystem , callback ) {
6579 this . buildInfo = { } ;
6680 this . buildMeta = { } ;
@@ -131,6 +145,7 @@ class MiniCssExtractPlugin {
131145 contentHashType : NS ,
132146 } ,
133147 identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
148+ hash : chunk . contentHash [ NS ] ,
134149 } ) ;
135150 }
136151 } ) ;
@@ -145,9 +160,29 @@ class MiniCssExtractPlugin {
145160 contentHashType : NS ,
146161 } ,
147162 identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
163+ hash : chunk . contentHash [ NS ] ,
148164 } ) ;
149165 }
150166 } ) ;
167+ compilation . mainTemplate . hooks . hashForChunk . tap (
168+ pluginName ,
169+ ( hash , chunk ) => {
170+ const { chunkFilename } = this . options ;
171+ if ( REGEXP_CHUNKHASH . test ( chunkFilename ) ) {
172+ hash . update ( JSON . stringify ( chunk . getChunkMaps ( true ) . hash ) ) ;
173+ }
174+ if ( REGEXP_CONTENTHASH . test ( chunkFilename ) ) {
175+ hash . update (
176+ JSON . stringify (
177+ chunk . getChunkMaps ( true ) . contentHash [ NS ] || { } ,
178+ ) ,
179+ ) ;
180+ }
181+ if ( REGEXP_NAME . test ( chunkFilename ) ) {
182+ hash . update ( JSON . stringify ( chunk . getChunkMaps ( true ) . name ) ) ;
183+ }
184+ } ,
185+ ) ;
151186 compilation . hooks . contentHash . tap ( pluginName , ( chunk ) => {
152187 const { outputOptions } = compilation ;
153188 const { hashFunction, hashDigest, hashDigestLength } = outputOptions ;
0 commit comments