1
1
module . exports = function ( publicPath , outputFilename ) {
2
2
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' ) ;
6
5
7
6
//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 ) ;
12
10
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 )
16
14
var head = document . getElementsByTagName ( 'head' ) [ 0 ]
17
15
var link = document . createElement ( 'link' )
18
16
@@ -38,4 +36,3 @@ module.exports = function(publicPath, outputFilename) {
38
36
}
39
37
}
40
38
}
41
-
0 commit comments