@@ -180,11 +180,11 @@ var Loader = function (data) {
180180 }
181181
182182 // Convert local path to unix format
183- localFilename = utils . pathToUnixFormat ( path . relative ( baseLocalFilename || options . path , localFilename ) ) ;
183+ var relativeFilename = utils . pathToUnixFormat ( path . relative ( baseLocalFilename || options . path , localFilename ) ) ;
184184
185185 return {
186186 promise : promise ,
187- localPath : localFilename
187+ localPath : relativeFilename
188188 }
189189 }
190190
@@ -235,32 +235,35 @@ var Loader = function (data) {
235235 function loadCssSources ( text , cssRemotePath , cssLocalPath ) {
236236 var cssLocalDirname = cssLocalPath ? path . dirname ( cssLocalPath ) : options . path ,
237237 commentRegexp = / \/ \* ( [ \s \S ] * ?) \* \/ / g,
238- urlRegexp = / ( @ i m p o r t [ \s ] * ) { 0 , 1 } u r l [ \s ] * \( [ \s ' " ] * ( .+ ?) [ \s ' " ] * \) / gi,
239- importRegexp = / @ i m p o r t [ \s ] * [ ' " ] { 0 , 1 } [ \s ] * ( .+ ?) [ \s ] * [ ' " ] { 0 , 1 } ; / gi,
240- urlMatch ,
241- urlPromises = [ ] ,
242- urlsToLoad = [ ] ;
238+ sourcesRegexps = [
239+ / ( u r l [ \s ] * \( [ \s ' " ] * ) ( .+ ?) ( [ \s ' " ] * \) ) / gi,
240+ / ( @ i m p o r t [ \s ] * [ ' " ] ? [ \s ] * ) ( .+ ?) ( [ \s ] * [ ' " ] ? ; ) / gi,
241+ / ( @ i m p o r t [ \s ] * u r l [ \s ] * \( [ \s ' " ] * ) ( .+ ?) ( [ \s ' " ] * \) ) / gi
242+ ] ,
243+ urlPromises = [ ] ;
243244
244245 // Remove all comments
245246 text = text . replace ( commentRegexp , '' ) ;
246247
247- // Foreach 'url() or @import url()'
248- while ( urlMatch = urlRegexp . exec ( text ) )
249- urlsToLoad . push ( urlMatch [ 2 ] ) ;
250- // Foreach @import
251- while ( urlMatch = importRegexp . exec ( text ) )
252- urlsToLoad . push ( urlMatch [ 1 ] ) ;
253-
254- _ . each ( urlsToLoad , function ( url ) {
255- // skip base64 encoded image and empty url
256- if ( url && ! utils . isEmbeddedImage ( url ) ) {
257- var urlAbsolutePath = utils . getAbsolutePath ( cssRemotePath , url ) ;
258- var result = loadFileFromUrl ( urlAbsolutePath , cssLocalDirname ) ;
259-
260- if ( result . promise )
261- urlPromises . push ( result . promise ) ;
262- if ( result . localPath )
263- text = text . replace ( url , result . localPath ) ;
248+ _ . each ( sourcesRegexps , function ( regexp ) {
249+ var textOrigin = text ,
250+ urlMatch ,
251+ url ;
252+
253+ while ( urlMatch = regexp . exec ( textOrigin ) ) {
254+ url = urlMatch [ 2 ] ;
255+ logger . log ( urlMatch [ 0 ] ) ;
256+
257+ if ( url && ! utils . isEmbeddedImage ( url ) ) {
258+ var urlAbsolutePath = utils . getAbsolutePath ( cssRemotePath , url ) ;
259+ var result = loadFileFromUrl ( urlAbsolutePath , cssLocalDirname ) ;
260+
261+ if ( result . promise )
262+ urlPromises . push ( result . promise ) ;
263+ if ( result . localPath ) {
264+ text = text . replace ( urlMatch [ 0 ] , urlMatch [ 1 ] + result . localPath + urlMatch [ 3 ] ) ;
265+ }
266+ }
264267 }
265268 } ) ;
266269
0 commit comments