Skip to content

Commit

Permalink
Merge pull request #33 from frenzzy/improve-hot-reload
Browse files Browse the repository at this point in the history
Improve Hot Reload
  • Loading branch information
koistya committed Apr 15, 2016
2 parents c7af229 + 640af4a commit 75257cf
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 75257cf

Please sign in to comment.