@@ -10,6 +10,10 @@ const NS = path.dirname(fs.realpathSync(__filename));
10
10
11
11
const pluginName = 'mini-css-extract-plugin' ;
12
12
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
+
13
17
class CssDependency extends webpack . Dependency {
14
18
constructor ( { identifier, content, media, sourceMap } , context , identifierIndex ) {
15
19
super ( ) ;
@@ -61,6 +65,16 @@ class CssModule extends webpack.Module {
61
65
return resource ;
62
66
}
63
67
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
+
64
78
build ( options , compilation , resolver , fileSystem , callback ) {
65
79
this . buildInfo = { } ;
66
80
this . buildMeta = { } ;
@@ -131,6 +145,7 @@ class MiniCssExtractPlugin {
131
145
contentHashType : NS ,
132
146
} ,
133
147
identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
148
+ hash : chunk . contentHash [ NS ] ,
134
149
} ) ;
135
150
}
136
151
} ) ;
@@ -145,9 +160,29 @@ class MiniCssExtractPlugin {
145
160
contentHashType : NS ,
146
161
} ,
147
162
identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
163
+ hash : chunk . contentHash [ NS ] ,
148
164
} ) ;
149
165
}
150
166
} ) ;
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
+ ) ;
151
186
compilation . hooks . contentHash . tap ( pluginName , ( chunk ) => {
152
187
const { outputOptions } = compilation ;
153
188
const { hashFunction, hashDigest, hashDigestLength } = outputOptions ;
0 commit comments