Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore original hot reloading behaviour for locals #419

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,23 @@ ${hmrCode}
const hmrCode = this.hot
? `
if (module.hot) {
module.hot.accept(
${loaderUtils.stringifyRequest(this, `!!${request}`)},
function() {
var newContent = require(${loaderUtils.stringifyRequest(
this,
`!!${request}`
)});

if (typeof newContent === 'string') {
newContent = [[module.id, newContent, '']];
}

var locals = (function(a, b) {
var key,
idx = 0;

for (key in a) {
if(!b || a[key] !== b[key]) return false;
idx++;
if (!content.locals) {
module.hot.accept(
${loaderUtils.stringifyRequest(this, `!!${request}`)},
function () {
var newContent = require(${loaderUtils.stringifyRequest(
this,
`!!${request}`
)});

if (typeof newContent === 'string') {
newContent = [[module.id, newContent, '']];
}

for (key in b) idx--;

return idx === 0;
}(content.locals, newContent.locals));

if (!locals) {
throw new Error('Aborting CSS HMR due to changed css-modules locals.');

update(newContent);
}

update(newContent);
}
);
)
}

module.hot.dispose(function() {
update();
Expand Down
1 change: 1 addition & 0 deletions test/manual/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ENABLE_SOURCE_MAP =
: false;

module.exports = {
devtool: ENABLE_SOURCE_MAP ? 'source-map' : false,
mode: 'development',
output: {
publicPath: '/dist/',
Expand Down