Skip to content

Commit c86dfac

Browse files
committed
fix($hmr): Support arbitrary origins in publicPath.
If the Webpack publicPath contains "http:" or "https:", treat it as the base URL for newly-loaded assets. Otherwise, continue to use the current window's location. Fixes faceyspacey#25.
1 parent 5c5c5d5 commit c86dfac

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

hotModuleReplacement.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
module.exports = function(publicPath, outputFilename) {
22
if (document) {
3-
var origin = document.location.protocol + '//' + document.location.hostname + (document.location.port ? ':' + document.location.port: '');
4-
var newHref = origin + publicPath + outputFilename
3+
var newHref = publicPath.match(/https?:/g) ? new URL(outputFilename, publicPath) : new URL(outputFilename, window.location);
54
var links = document.getElementsByTagName('link');
65

76
//update the stylesheet corresponding to `outputFilename`
87
for (var i = 0; i < links.length; i++) {
98
if (links[i].href) {
109
var oldChunk = new URL(links[i].href);
11-
var newChunk = new URL(newHref);
1210

13-
if (oldChunk.pathname === newChunk.pathname) {
11+
if (oldChunk.pathname === newHref.pathname) {
1412
var oldSheet = links[i]
15-
var url = newHref + '?' + (+new Date)
13+
var url = newHref.href + '?' + (+new Date)
1614
var head = document.getElementsByTagName('head')[0]
1715
var link = document.createElement('link')
1816

0 commit comments

Comments
 (0)