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