@@ -58,11 +58,9 @@ class MiniCssExtractPlugin {
58
58
this . content = content ;
59
59
this . media = media ;
60
60
this . sourceMap = sourceMap ;
61
- this . buildInfo = {
62
- assets,
63
- assetsInfo,
64
- } ;
65
- this . buildMeta = { } ;
61
+ this . assets = assets ;
62
+ this . assetsInfo = assetsInfo ;
63
+ this . _needBuild = true ;
66
64
}
67
65
68
66
// no source() so webpack 4 doesn't do add stuff to the bundle
@@ -103,34 +101,60 @@ class MiniCssExtractPlugin {
103
101
}
104
102
105
103
updateCacheModule ( module ) {
106
- this . content = module . content ;
107
- this . media = module . media ;
108
- this . sourceMap = module . sourceMap ;
104
+ if (
105
+ this . content !== module . content ||
106
+ this . media !== module . media ||
107
+ this . sourceMap !== module . sourceMap ||
108
+ this . assets !== module . assets ||
109
+ this . assetsInfo !== module . assetsInfo
110
+ ) {
111
+ this . _needBuild = true ;
112
+
113
+ this . content = module . content ;
114
+ this . media = module . media ;
115
+ this . sourceMap = module . sourceMap ;
116
+ this . assets = module . assets ;
117
+ this . assetsInfo = module . assetsInfo ;
118
+ }
109
119
}
110
120
111
121
// eslint-disable-next-line class-methods-use-this
112
122
needRebuild ( ) {
113
- return true ;
123
+ return this . _needBuild ;
114
124
}
115
125
116
126
// eslint-disable-next-line class-methods-use-this
117
127
needBuild ( context , callback ) {
118
- callback ( null , false ) ;
128
+ callback ( null , this . _needBuild ) ;
119
129
}
120
130
121
131
build ( options , compilation , resolver , fileSystem , callback ) {
122
- this . buildInfo = { } ;
132
+ this . buildInfo = {
133
+ assets : this . assets ,
134
+ assetsInfo : this . assetsInfo ,
135
+ cacheable : true ,
136
+ hash : this . _computeHash ( compilation . outputOptions . hashFunction ) ,
137
+ } ;
123
138
this . buildMeta = { } ;
139
+ this . _needBuild = false ;
124
140
125
141
callback ( ) ;
126
142
}
127
143
128
- updateHash ( hash , context ) {
129
- super . updateHash ( hash , context ) ;
144
+ _computeHash ( hashFunction ) {
145
+ const hash = webpack . util . createHash ( hashFunction ) ;
130
146
131
147
hash . update ( this . content ) ;
132
148
hash . update ( this . media || '' ) ;
133
- hash . update ( this . sourceMap ? JSON . stringify ( this . sourceMap ) : '' ) ;
149
+ hash . update ( this . sourceMap || '' ) ;
150
+
151
+ return hash . digest ( 'hex' ) ;
152
+ }
153
+
154
+ updateHash ( hash , context ) {
155
+ super . updateHash ( hash , context ) ;
156
+
157
+ hash . update ( this . buildInfo . hash ) ;
134
158
}
135
159
136
160
serialize ( context ) {
@@ -142,12 +166,17 @@ class MiniCssExtractPlugin {
142
166
write ( this . content ) ;
143
167
write ( this . media ) ;
144
168
write ( this . sourceMap ) ;
145
- write ( this . buildInfo ) ;
169
+ write ( this . assets ) ;
170
+ write ( this . assetsInfo ) ;
171
+
172
+ write ( this . _needBuild ) ;
146
173
147
174
super . serialize ( context ) ;
148
175
}
149
176
150
177
deserialize ( context ) {
178
+ this . _needBuild = context . read ( ) ;
179
+
151
180
super . deserialize ( context ) ;
152
181
}
153
182
}
@@ -176,7 +205,8 @@ class MiniCssExtractPlugin {
176
205
const content = read ( ) ;
177
206
const media = read ( ) ;
178
207
const sourceMap = read ( ) ;
179
- const { assets, assetsInfo } = read ( ) ;
208
+ const assets = read ( ) ;
209
+ const assetsInfo = read ( ) ;
180
210
181
211
const dep = new CssModule ( {
182
212
context : contextModule ,
@@ -364,7 +394,7 @@ class MiniCssExtractPlugin {
364
394
if ( this . options . experimentalUseImportModule ) {
365
395
if ( ! compiler . options . experiments ) {
366
396
throw new Error (
367
- 'experimentalUseImportModule is only support for webpack >= 5.32.0 '
397
+ 'experimentalUseImportModule is only support for webpack >= 5.33.2 '
368
398
) ;
369
399
}
370
400
if ( typeof compiler . options . experiments . executeModule === 'undefined' ) {
@@ -613,8 +643,14 @@ class MiniCssExtractPlugin {
613
643
: webpack . util . createHash ;
614
644
const hash = createHash ( hashFunction ) ;
615
645
616
- for ( const m of modules ) {
617
- m . updateHash ( hash , { chunkGraph } ) ;
646
+ if ( isWebpack4 ) {
647
+ for ( const m of modules ) {
648
+ m . updateHash ( hash ) ;
649
+ }
650
+ } else {
651
+ for ( const m of modules ) {
652
+ hash . update ( chunkGraph . getModuleHash ( m , chunk . runtime ) ) ;
653
+ }
618
654
}
619
655
620
656
// eslint-disable-next-line no-param-reassign
0 commit comments