forked from faceyspacey/extract-css-chunks-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotModuleReplacement.js
24 lines (22 loc) · 894 Bytes
/
hotModuleReplacement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module.exports = function(publicPath, outputFilename) {
if (document) {
var origin = document.location.protocol +
'//' + document.location.hostname + (document.location.port ? ':' + document.location.port: '');
var newHref = origin + publicPath + outputFilename;
var styleSheets = document.getElementsByTagName('link');
//update the stylesheet corresponding to `outputFilename`
for (var i = 0; i < styleSheets.length; i++) {
if (styleSheets[i].href) {
var oldChunk = styleSheets[i].href.split('.')[0];
var newChunk = newHref.split('.')[0];
if (oldChunk === newChunk) {
// date insures sheets update when [contenthash] is not used in file names
var url = newHref + '?' + (+new Date);
styleSheets[i].href = url;
console.log('[HMR]', 'Reload css: ', url);
break;
}
}
}
}
};