Skip to content

Commit

Permalink
Improve Hot Reload
Browse files Browse the repository at this point in the history
Now, if you require styles for the second time of from another place, it will return the new styles and not those which you seen before first hot reload.

fix #32
  • Loading branch information
frenzzy committed Apr 14, 2016
1 parent b033833 commit 640af4a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.js
Expand Up @@ -27,22 +27,23 @@ module.exports.pitch = function pitch(remainingRequest) {
module.exports = content.locals || {};
module.exports._getCss = function() { return content.toString(); };
module.exports._insertCss = insertCss.bind(null, content);
module.exports._insertCss = function(options) { return insertCss(content, options) };
`;

output += this.debug ? `
var removeCss = function() {};
// Hot Module Replacement
// https://webpack.github.io/docs/hot-module-replacement
// Only activated in browser context
if (module.hot && typeof window !== 'undefined' && window.document) {
var removeCss = function() {};
module.hot.accept(${stringifyRequest(this, `!!${remainingRequest}`)}, function() {
var newContent = require(${stringifyRequest(this, `!!${remainingRequest}`)});
if (typeof newContent === 'string') {
newContent = [[module.id, content, '']];
content = require(${stringifyRequest(this, `!!${remainingRequest}`)});
if (typeof content === 'string') {
content = [[module.id, content, '']];
}
removeCss = insertCss(newContent, { replace: true });
removeCss = insertCss(content, { replace: true });
});
module.hot.dispose(function() { removeCss(); });
}
Expand Down

0 comments on commit 640af4a

Please sign in to comment.