Skip to content

Commit

Permalink
refactor: restore hmr for lazy styles after refactor (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 5, 2019
1 parent 3824f83 commit f4cf0d2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ if (module.hot) {
var lastRefs = module.hot.data && module.hot.data.refs || 0;
if (lastRefs) {
exports.ref();
exports.use();
if (!content.locals) {
refs = lastRefs;
}
Expand Down Expand Up @@ -94,8 +95,13 @@ var options = ${JSON.stringify(options)};
options.insert = ${insert};
options.singleton = ${isSingleton};
if (typeof content === 'string') content = [[module.id, content, '']];
if (content.locals) exports.locals = content.locals;
if (typeof content === 'string') {
content = [[module.id, content, '']];
}
if (content.locals) {
exports.locals = content.locals;
}
exports.use = function() {
if (!(refs++)) {
Expand Down Expand Up @@ -134,8 +140,9 @@ if (module.hot) {
`!!${request}`
)});
if (typeof newContent === 'string')
if (typeof newContent === 'string') {
newContent = [[module.id, newContent, '']];
}
var locals = (function(a, b) {
var key,
Expand All @@ -151,8 +158,9 @@ if (module.hot) {
return idx === 0;
}(content.locals, newContent.locals));
if (!locals)
if (!locals) {
throw new Error('Aborting CSS HMR due to changed css-modules locals.');
}
update(newContent);
}
Expand All @@ -169,9 +177,9 @@ if (module.hot) {
`!!${request}`
)});
if (typeof content === 'string') content = [[module.id, content, '']];
var insertInto;
if (typeof content === 'string') {
content = [[module.id, content, '']];
}
var options = ${JSON.stringify(options)}
Expand All @@ -183,7 +191,9 @@ var update = require(${loaderUtils.stringifyRequest(
`!${path.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`
)})(content, options);
if (content.locals) module.exports = content.locals;
if (content.locals) {
module.exports = content.locals;
}
${hmrCode}`;
}
}
Expand Down

0 comments on commit f4cf0d2

Please sign in to comment.