From b693232bc263b759f5df48018681dd483059a39c Mon Sep 17 00:00:00 2001 From: lwdgit <1127622940@qq.com> Date: Tue, 1 Sep 2015 10:54:15 +0800 Subject: [PATCH] fix importer and watch md5 #1 --- README.md | 2 +- index.js | 62 ++++++++++++++++++++++++++-------------------------- package.json | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ff9999e..8988b26 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ A parser plugin for reasy to compile sass file. //reasy-conf.js reasy.match('**.scss', { rExt: '.css', // from .scss to .css - parser: reasy.plugin('sass') + parser: fis.plugin('sass') } ``` diff --git a/index.js b/index.js index 617e4a3..70bf5cf 100644 --- a/index.js +++ b/index.js @@ -145,37 +145,37 @@ module.exports = function(content, file, conf) { var includePaths = opts.includePaths; var sources = [file.subpath]; - // opts.importer = function(url, prev, done) { - // var localPaths = includePaths.concat(); - // var prevFile = find(prev, includePaths); - - // if (prevFile) { - // localPaths.unshift(prevFile.dirname); - // } - - // var target = find(url, localPaths); - - // if (!target) { - // throw new Error('Can\'t find `' + url +'` in `' + prev + '`'); - // } - - // var content = target.getContent(); - // content = fixSourcePath(content, target); - - // if (file.cache) { - // file.cache.addDeps(target.realpath); - // } - // //解决include_path 内import导致subpath为空报错问题 - // if(!target.subpath){ - // target.subpath = path.relative(root, target.realpath); - // } - // ~sources.indexOf(target.subpath) || sources.push(target.subpath); - - // done({ - // file: target.subpath, - // contents: content - // }); - // }; + opts.importer = function(url, prev, done) { + var localPaths = includePaths.concat(); + var prevFile = find(prev, includePaths); + + if (prevFile) { + localPaths.unshift(prevFile.dirname); + } + + var target = find(url, localPaths); + + if (!target) { + throw new Error('Can\'t find `' + url +'` in `' + prev + '`'); + } + + var content = target.getContent(); + content = fixSourcePath(content, target); + + if (file.cache) { + file.cache.addDeps(target.realpath); + } + //解决include_path 内import导致subpath为空报错问题 + if(!target.subpath){ + target.subpath = path.relative(root, target.realpath); + } + ~sources.indexOf(target.subpath) || sources.push(target.subpath); + + return { + file: target.subpath, + contents: content + }; + }; if (opts.sourceMap) { diff --git a/package.json b/package.json index 52d3378..e68bacf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "reasy-parser-sass", "description": "A parser plugin for reasy to compile sass file.", - "version": "1.1.6", + "version": "1.1.7", "keywords": [ "fis", "sass"