@@ -16,9 +16,19 @@ import schema from './loader-options.json';
16
16
const pluginName = 'mini-css-extract-plugin' ;
17
17
18
18
function hotLoader ( content , context ) {
19
- const accept = context . locals
20
- ? ''
21
- : 'module.hot.accept(undefined, cssReload);' ;
19
+ const accept = `
20
+ if (!_locals || module.hot.invalidate) {
21
+ if (module.hot.invalidate &&
22
+ module.hot.data &&
23
+ module.hot.data.oldLocals &&
24
+ !isEqualLocals(module.hot.data.oldLocals, _locals, ${ JSON . stringify (
25
+ context . namedExport
26
+ ) } )) {
27
+ module.hot.invalidate();
28
+ } else {
29
+ module.hot.accept();
30
+ }
31
+ }` ;
22
32
23
33
return `${ content }
24
34
if(module.hot) {
@@ -30,7 +40,15 @@ function hotLoader(content, context) {
30
40
...context . options ,
31
41
locals : ! ! context . locals ,
32
42
} ) } );
33
- module.hot.dispose(cssReload);
43
+ var _locals = ${ JSON . stringify ( context . locals ) } ;
44
+ var isEqualLocals = require(${ loaderUtils . stringifyRequest (
45
+ context . context ,
46
+ path . join ( __dirname , 'hmr/isEqualLocals.js' )
47
+ ) } );
48
+ module.hot.dispose(function(data) {
49
+ cssReload();
50
+ data.oldLocals = _locals;
51
+ });
34
52
${ accept }
35
53
}
36
54
` ;
@@ -269,7 +287,12 @@ export function pitch(request) {
269
287
let resultSource = `// extracted by ${ pluginName } ` ;
270
288
271
289
resultSource += this . hot
272
- ? hotLoader ( result , { context : this . context , options, locals } )
290
+ ? hotLoader ( result , {
291
+ context : this . context ,
292
+ options,
293
+ locals,
294
+ namedExport,
295
+ } )
273
296
: result ;
274
297
275
298
return callback ( null , resultSource ) ;
0 commit comments