@@ -16,9 +16,19 @@ import schema from './loader-options.json';
1616const pluginName = 'mini-css-extract-plugin' ;
1717
1818function 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+ }` ;
2232
2333 return `${ content }
2434 if(module.hot) {
@@ -30,7 +40,15 @@ function hotLoader(content, context) {
3040 ...context . options ,
3141 locals : ! ! context . locals ,
3242 } ) } );
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+ });
3452 ${ accept }
3553 }
3654 ` ;
@@ -269,7 +287,12 @@ export function pitch(request) {
269287 let resultSource = `// extracted by ${ pluginName } ` ;
270288
271289 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+ } )
273296 : result ;
274297
275298 return callback ( null , resultSource ) ;
0 commit comments