Skip to content

Commit 22d7d38

Browse files
committed
- Update postcss to 5.x
- Fix #38
1 parent a81be90 commit 22d7d38

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function imageSetMixin(decl, i) {
413413
}
414414
} else if (decl.value.indexOf('url(') != -1) {
415415
//没有image-set,执行以下
416-
var retinaPaths = returnURL(decl.value, reNO_SETURL) //获取第一个url图片的路径
416+
var retinaPaths = returnURL(decl.value, reNO_SETURL); //获取第一个url图片的路径
417417

418418
// var retinaSizes = sizeOf(getAbsolutePath(retinaPaths[0][2]));
419419

@@ -490,7 +490,7 @@ var cssgraceRule = function(rule, i) {
490490

491491
//根据decl.value的值,返回paths数组
492492
function returnURL(val, reg) {
493-
var result, paths = []
493+
var result, paths = [];
494494
while ((result = reg.exec(val)) != null) {
495495
paths.push(result);
496496
}
@@ -505,17 +505,22 @@ function getAbsolutePath(sourcePath) {
505505
return path.resolve(currentFilePath, sourcePath.split("?")[0]);
506506
}
507507

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+
508514
// PostCSS Processor
509-
var cssprocess = function(css, opts) {
515+
var cssprocess = function(css) {
510516
//保存当前处理文件路径
511-
currentFilePath = path.dirname(opts.from);
517+
currentFilePath = getCurrentFilePath(css) || currentFilePath;
512518
css.eachRule(cssgraceRule);
513519
}
514520

515521
var pack = function(css, opts) {
516522
//保存当前处理文件路径
517523
currentFilePath = path.dirname(opts.from);
518-
console.log(currentFilePath);
519524
return postcss(cssprocess).process(css, opts).css;
520525
}
521526

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@
2323
"postproccessor"
2424
],
2525
"dependencies": {
26+
"postcss": "^5.0.0",
2627
"image-size": "^0.3.5"
2728
},
28-
"peerDependencies": {
29-
"postcss": "^4.0.0"
30-
},
3129
"devDependencies": {
32-
"postcss": "^4.0.0",
3330
"tape": "^3.0.0"
3431
},
3532
"scripts": {

0 commit comments

Comments
 (0)