@@ -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,17 @@ class CssModule extends webpack.Module {
61
65
return resource ;
62
66
}
63
67
68
+ updateCacheModule ( module ) {
69
+ console . log ( 'updateCacheModule' , module . content ) ;
70
+ this . content = module . content ;
71
+ this . media = module . media ;
72
+ this . sourceMap = module . sourceMap ;
73
+ }
74
+
75
+ needRebuild ( ) {
76
+ return true ;
77
+ }
78
+
64
79
build ( options , compilation , resolver , fileSystem , callback ) {
65
80
this . buildInfo = { } ;
66
81
this . buildMeta = { } ;
@@ -131,6 +146,7 @@ class MiniCssExtractPlugin {
131
146
contentHashType : NS ,
132
147
} ,
133
148
identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
149
+ hash : chunk . contentHash [ NS ] ,
134
150
} ) ;
135
151
}
136
152
} ) ;
@@ -145,9 +161,29 @@ class MiniCssExtractPlugin {
145
161
contentHashType : NS ,
146
162
} ,
147
163
identifier : `mini-css-extract-plugin.${ chunk . id } ` ,
164
+ hash : chunk . contentHash [ NS ] ,
148
165
} ) ;
149
166
}
150
167
} ) ;
168
+ compilation . mainTemplate . hooks . hashForChunk . tap (
169
+ pluginName ,
170
+ ( hash , chunk ) => {
171
+ const { chunkFilename } = this . options ;
172
+ if ( REGEXP_CHUNKHASH . test ( chunkFilename ) ) {
173
+ hash . update ( JSON . stringify ( chunk . getChunkMaps ( true ) . hash ) ) ;
174
+ }
175
+ if ( REGEXP_CONTENTHASH . test ( chunkFilename ) ) {
176
+ hash . update (
177
+ JSON . stringify (
178
+ chunk . getChunkMaps ( true ) . contentHash [ NS ] || { } ,
179
+ ) ,
180
+ ) ;
181
+ }
182
+ if ( REGEXP_NAME . test ( chunkFilename ) ) {
183
+ hash . update ( JSON . stringify ( chunk . getChunkMaps ( true ) . name ) ) ;
184
+ }
185
+ } ,
186
+ ) ;
151
187
compilation . hooks . contentHash . tap ( pluginName , ( chunk ) => {
152
188
const { outputOptions } = compilation ;
153
189
const { hashFunction, hashDigest, hashDigestLength } = outputOptions ;
0 commit comments