@@ -26,7 +26,7 @@ function getLoaderConfig(context) {
26
26
module . exports = function ( content ) {
27
27
this . cacheable && this . cacheable ( ) ;
28
28
var config = getLoaderConfig ( this ) ;
29
- var attributes = [ "img:src" ] ;
29
+ var attributes = [ "img:src" , "img:srcset" ] ;
30
30
if ( config . attrs !== undefined ) {
31
31
if ( typeof config . attrs === "string" )
32
32
attributes = config . attrs . split ( " " ) ;
@@ -45,20 +45,30 @@ module.exports = function(content) {
45
45
var data = { } ;
46
46
content = [ content ] ;
47
47
links . forEach ( function ( link ) {
48
- if ( ! loaderUtils . isUrlRequest ( link . value , root ) ) return ;
49
-
50
- var uri = url . parse ( link . value ) ;
51
- if ( uri . hash !== null && uri . hash !== undefined ) {
52
- uri . hash = null ;
53
- link . value = uri . format ( ) ;
54
- link . length = link . value . length ;
55
- }
48
+ var newValue = link . value . split ( "," ) ;
49
+ var newValue = newValue . map ( function ( value ) {
50
+ var valueArray = value . trim ( ) . split ( " " ) ;
51
+ var obj = {
52
+ value : valueArray . shift ( ) ,
53
+ additional : valueArray ,
54
+ } ;
55
+ if ( ! loaderUtils . isUrlRequest ( obj . value , root ) ) return ;
56
+ var uri = url . parse ( obj . value ) ;
57
+ if ( uri . hash !== null && uri . hash !== undefined ) {
58
+ obj . hash = uri . hash ;
59
+ uri . hash = null ;
60
+ obj . value = uri . format ( ) ;
61
+ }
62
+ return obj ;
63
+ } ) ;
56
64
57
65
do {
58
66
var ident = randomIdent ( ) ;
59
67
} while ( data [ ident ] ) ;
60
- data [ ident ] = link . value ;
68
+ data [ ident ] = newValue ;
61
69
var x = content . pop ( ) ;
70
+
71
+
62
72
content . push ( x . substr ( link . start + link . length ) ) ;
63
73
content . push ( ident ) ;
64
74
content . push ( x . substr ( 0 , link . start ) ) ;
@@ -95,9 +105,16 @@ module.exports = function(content) {
95
105
} else {
96
106
content = JSON . stringify ( content ) ;
97
107
}
98
-
99
108
return "module.exports = " + content . replace ( / x x x H T M L L I N K x x x [ 0 - 9 \. ] + x x x / g, function ( match ) {
100
109
if ( ! data [ match ] ) return match ;
101
- return '" + require(' + JSON . stringify ( loaderUtils . urlToRequest ( data [ match ] , root ) ) + ') + "' ;
110
+ return data [ match ] . reduce ( function ( pV , cV , index , array ) {
111
+
112
+ var hash = cV . hash || "" ;
113
+ var additional = cV . additional . length != 0 ? " " + cV . additional . join ( " " ) : "" ;
114
+ if ( index != array . length - 1 ) {
115
+ additional += "," ;
116
+ }
117
+ return pV + '" + require(' + JSON . stringify ( loaderUtils . urlToRequest ( cV . value , root ) ) + ') + "' + hash + additional ;
118
+ } , "" ) ;
102
119
} ) + ";" ;
103
120
}
0 commit comments