@@ -58,11 +58,9 @@ class MiniCssExtractPlugin {
5858 this . content = content ;
5959 this . media = media ;
6060 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 ;
6664 }
6765
6866 // no source() so webpack 4 doesn't do add stuff to the bundle
@@ -103,34 +101,60 @@ class MiniCssExtractPlugin {
103101 }
104102
105103 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+ }
109119 }
110120
111121 // eslint-disable-next-line class-methods-use-this
112122 needRebuild ( ) {
113- return true ;
123+ return this . _needBuild ;
114124 }
115125
116126 // eslint-disable-next-line class-methods-use-this
117127 needBuild ( context , callback ) {
118- callback ( null , false ) ;
128+ callback ( null , this . _needBuild ) ;
119129 }
120130
121131 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+ } ;
123138 this . buildMeta = { } ;
139+ this . _needBuild = false ;
124140
125141 callback ( ) ;
126142 }
127143
128- updateHash ( hash , context ) {
129- super . updateHash ( hash , context ) ;
144+ _computeHash ( hashFunction ) {
145+ const hash = webpack . util . createHash ( hashFunction ) ;
130146
131147 hash . update ( this . content ) ;
132148 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 ) ;
134158 }
135159
136160 serialize ( context ) {
@@ -142,12 +166,17 @@ class MiniCssExtractPlugin {
142166 write ( this . content ) ;
143167 write ( this . media ) ;
144168 write ( this . sourceMap ) ;
145- write ( this . buildInfo ) ;
169+ write ( this . assets ) ;
170+ write ( this . assetsInfo ) ;
171+
172+ write ( this . _needBuild ) ;
146173
147174 super . serialize ( context ) ;
148175 }
149176
150177 deserialize ( context ) {
178+ this . _needBuild = context . read ( ) ;
179+
151180 super . deserialize ( context ) ;
152181 }
153182 }
@@ -176,7 +205,8 @@ class MiniCssExtractPlugin {
176205 const content = read ( ) ;
177206 const media = read ( ) ;
178207 const sourceMap = read ( ) ;
179- const { assets, assetsInfo } = read ( ) ;
208+ const assets = read ( ) ;
209+ const assetsInfo = read ( ) ;
180210
181211 const dep = new CssModule ( {
182212 context : contextModule ,
@@ -364,7 +394,7 @@ class MiniCssExtractPlugin {
364394 if ( this . options . experimentalUseImportModule ) {
365395 if ( ! compiler . options . experiments ) {
366396 throw new Error (
367- 'experimentalUseImportModule is only support for webpack >= 5.32.0 '
397+ 'experimentalUseImportModule is only support for webpack >= 5.33.2 '
368398 ) ;
369399 }
370400 if ( typeof compiler . options . experiments . executeModule === 'undefined' ) {
@@ -613,8 +643,14 @@ class MiniCssExtractPlugin {
613643 : webpack . util . createHash ;
614644 const hash = createHash ( hashFunction ) ;
615645
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+ }
618654 }
619655
620656 // eslint-disable-next-line no-param-reassign
0 commit comments