@@ -413,7 +413,7 @@ function imageSetMixin(decl, i) {
413
413
}
414
414
} else if ( decl . value . indexOf ( 'url(' ) != - 1 ) {
415
415
//没有image-set,执行以下
416
- var retinaPaths = returnURL ( decl . value , reNO_SETURL ) //获取第一个url图片的路径
416
+ var retinaPaths = returnURL ( decl . value , reNO_SETURL ) ; //获取第一个url图片的路径
417
417
418
418
// var retinaSizes = sizeOf(getAbsolutePath(retinaPaths[0][2]));
419
419
@@ -490,7 +490,7 @@ var cssgraceRule = function(rule, i) {
490
490
491
491
//根据decl.value的值,返回paths数组
492
492
function returnURL ( val , reg ) {
493
- var result , paths = [ ]
493
+ var result , paths = [ ] ;
494
494
while ( ( result = reg . exec ( val ) ) != null ) {
495
495
paths . push ( result ) ;
496
496
}
@@ -505,17 +505,22 @@ function getAbsolutePath(sourcePath) {
505
505
return path . resolve ( currentFilePath , sourcePath . split ( "?" ) [ 0 ] ) ;
506
506
}
507
507
508
+ function getCurrentFilePath ( node ) {
509
+ var inputfile = node . source && node . source . input && node . source . input . file ;
510
+ var dirname = inputfile ? path . dirname ( inputfile ) : '' ;
511
+ return dirname ;
512
+ }
513
+
508
514
// PostCSS Processor
509
- var cssprocess = function ( css , opts ) {
515
+ var cssprocess = function ( css ) {
510
516
//保存当前处理文件路径
511
- currentFilePath = path . dirname ( opts . from ) ;
517
+ currentFilePath = getCurrentFilePath ( css ) || currentFilePath ;
512
518
css . eachRule ( cssgraceRule ) ;
513
519
}
514
520
515
521
var pack = function ( css , opts ) {
516
522
//保存当前处理文件路径
517
523
currentFilePath = path . dirname ( opts . from ) ;
518
- console . log ( currentFilePath ) ;
519
524
return postcss ( cssprocess ) . process ( css , opts ) . css ;
520
525
}
521
526
0 commit comments