11module . 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
5- var styleSheets = document . getElementsByTagName ( 'link' ) ;
3+ var newHref = publicPath . match ( / h t t p s ? : / g) ? new URL ( outputFilename , publicPath ) : new URL ( publicPath + outputFilename , window . location ) ;
4+ var links = document . getElementsByTagName ( 'link' ) ;
65
76 //update the stylesheet corresponding to `outputFilename`
8- for ( var i = 0 ; i < styleSheets . length ; i ++ ) {
9- if ( styleSheets [ i ] . href ) {
10- var oldChunk = styleSheets [ i ] . href . split ( '.' ) [ 0 ] ;
11- var newChunk = newHref . split ( '.' ) [ 0 ] ;
7+ for ( var i = 0 ; i < links . length ; i ++ ) {
8+ if ( links [ i ] . href ) {
9+ var oldChunk = new URL ( links [ i ] . href ) ;
1210
13- if ( oldChunk === newChunk ) {
14- var oldSheet = styleSheets [ i ]
15- var url = newHref + '?' + ( + new Date )
11+ if ( oldChunk . pathname === newHref . pathname ) {
12+ var oldSheet = links [ i ]
13+ var url = newHref . href + '?' + ( + new Date )
1614 var head = document . getElementsByTagName ( 'head' ) [ 0 ]
1715 var link = document . createElement ( 'link' )
1816
@@ -38,4 +36,3 @@ module.exports = function(publicPath, outputFilename) {
3836 }
3937 }
4038}
41-
0 commit comments