Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 11ac516

Browse files
committed
Move to runtime
Still double requests on load Also leaks path to runtime in bundle
1 parent 676942a commit 11ac516

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

hotModuleReplacement.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = function(compilationHash, publicPath, outputFilename) {
2+
if (document) {
3+
var styleSheets = document.getElementsByTagName('link');
4+
for (var i = 0; i < styleSheets.length; i++) {
5+
if (styleSheets[i].href) {
6+
var hrefUrl = styleSheets[i].href.split('?');
7+
var href = hrefUrl[0];
8+
var hash = hrefUrl[1];
9+
if (hash !== compilationHash && href === document.location.origin + publicPath + outputFilename) {
10+
var url = href + '?' + compilationHash;
11+
styleSheets[i].href = url;
12+
console.log('[HMR]', 'Reload css: ', url);
13+
break;
14+
}
15+
}
16+
}
17+
}
18+
}

loader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ var NodeTargetPlugin = require("webpack/lib/node/NodeTargetPlugin");
88
var LibraryTemplatePlugin = require("webpack/lib/LibraryTemplatePlugin");
99
var SingleEntryPlugin = require("webpack/lib/SingleEntryPlugin");
1010
var LimitChunkCountPlugin = require("webpack/lib/optimize/LimitChunkCountPlugin");
11+
12+
var extractTextPluginHmrRuntime = require.resolve("./hotModuleReplacement.js");
13+
1114
module.exports = function(source) {
1215
if(this.cacheable) this.cacheable();
13-
return source;
16+
// Even though this gets overwritten if extract+remove are true, without it, the runtime doesn't get added to the chunk
17+
return "if(module.hot){require('" + extractTextPluginHmrRuntime + "');}\n" + source;
1418
};
1519
module.exports.pitch = function(request) {
1620
if(this.cacheable) this.cacheable();
@@ -109,7 +113,7 @@ module.exports.pitch = function(request) {
109113
if (text.locals) {
110114
resultSource += "\nmodule.exports = " + JSON.stringify(text.locals) + ";";
111115
}
112-
resultSource += "\nfunction replaceStylesheet(styleSheet,url){styleSheet.href=url;console.log('[HMR]','Reload css: ',url)}\nfunction cssReload(compilationHash,publicPath,outputFilename){if(document){var styleSheets=document.getElementsByTagName('link');for(var i=0;i<styleSheets.length;i++){if(styleSheets[i].href){var hrefUrl=styleSheets[i].href.split('?');var href=hrefUrl[0];var hash=hrefUrl[1];if(hash!==compilationHash&&href===document.location.origin+publicPath+outputFilename){replaceStylesheet(styleSheets[i],href+'?'+compilationHash);break}}}}}\nif(module.hot){\nmodule.hot.accept();\ncssReload('%%extracted-hash%%','" + publicPath + "','%%extracted-file%%');}";
116+
resultSource += "\nif(module.hot){\nmodule.hot.accept();\nrequire('" + extractTextPluginHmrRuntime + "')('%%extracted-hash%%','" + publicPath + "','%%extracted-file%%');}";
113117
}
114118
} catch(e) {
115119
return callback(e);

0 commit comments

Comments
 (0)