lib/combo.js
function(content,filePath) {
        'use strict';

        var self = this;

        var regImport = /@import\s*(url)?\(?['"]([^'"%]+)\.css['"]\)?[^;]*;/ig,
            regImageOrFont = /(url)?\(['"]?([^:\)]+\.(png|jpg|gif|jpeg|ttf|eot|woff|svg))([^\)]*)['"]?\)/ig,
            importResult,
            picAndFontResult;

        var importFilePath = path.dirname(path.resolve(self.config.sourceDir,filePath));

        // 替换import
        importResult = regImport.exec(content);
        if (typeof importResult !== 'undefined' && importResult && importResult[2]) {
            var importAbsoluteUrl = path.resolve(importFilePath,importResult[2]);
            // 用%号表示已经替换好的import路径，后续会再去掉百分号,这里替换的时
            // 候要注意全局的替换
            var regimportReplace = new RegExp(importResult[2],'g');
            content = content.replace(regimportReplace, "%" + path.relative(self.config.sourceDir,importAbsoluteUrl));
            return self.modifySubImportsPath(content, filePath);
        }
        // 替换图片和font的路径
        picAndFontResult = regImageOrFont.exec(content);
        if (typeof picAndFontResult !== 'undefined' && picAndFontResult && picAndFontResult[2] && !/^\/\/[^\/]+/.test(picAndFontResult[2])) {
            var regpicReplace = new RegExp(picAndFontResult[2],'g');
            var picAbsolutePath = path.resolve(importFilePath,picAndFontResult[2]);
            //解决win平台下路径的斜杠问题
            var isWin = (process.platform === 'win32');
            var _path = path.relative(self.config.sourceDir,picAbsolutePath);
            if(isWin){
                _path = path.relative(self.config.sourceDir,picAbsolutePath).split(path.sep).join("\/");
            }
            // 用：号表示已经替换好的import路径，后续会再去掉冒号
            content = content.replace(regpicReplace, ":" + _path);
            return self.modifySubImportsPath(content, filePath);
        }
        return content;
    }
function(content,filePath) {
        'use strict';

        var self = this;

        var regImport = /@import\s*(url)?\(?['"]([^'"%]+)\.css['"]\)?[^;]*;/ig,
            regImageOrFont = /(url)?\(['"]?([^:\)]+\.(png|jpg|gif|jpeg|ttf|eot|woff|svg))([^\)]*)['"]?\)/ig,
            importResult,
            picAndFontResult;

        var importFilePath = path.dirname(path.resolve(self.config.sourceDir,filePath));

        // 替换import
        importResult = regImport.exec(content);
        if (typeof importResult !== 'undefined' && importResult && importResult[2]) {
            var importAbsoluteUrl = path.resolve(importFilePath,importResult[2]);
            // 用%号表示已经替换好的import路径，后续会再去掉百分号,这里替换的时
            // 候要注意全局的替换
            var regimportReplace = new RegExp(importResult[2],'g');
            content = content.replace(regimportReplace, "%" + path.relative(self.config.sourceDir,importAbsoluteUrl));
            return self.modifySubImportsPath(content, filePath);
        }
        // 替换图片和font的路径
        picAndFontResult = regImageOrFont.exec(content);
        if (typeof picAndFontResult !== 'undefined' && picAndFontResult && picAndFontResult[2] && !/^\/\/[^\/]+/.test(picAndFontResult[2])) {
            var regpicReplace = new RegExp(picAndFontResult[2],'g');
            var picAbsolutePath = path.resolve(importFilePath,picAndFontResult[2]);
            //解决win平台下路径的斜杠问题
            var isWin = (process.platform === 'win32');
            var _path = path.relative(self.config.sourceDir,picAbsolutePath);
            if(isWin){
                _path = path.relative(self.config.sourceDir,picAbsolutePath).split(path.sep).join("\/");
            }
            // 用：号表示已经替换好的import路径，后续会再去掉冒号
            content = content.replace(regpicReplace, ":" + _path);
            return self.modifySubImportsPath(content, filePath);
        }
        return content;
    }
修改子文件import的相对路径 子文件夹中所有的相对路径都要进行转换 先看一下什么形式的地址需要转换 @import "./mods/import.css" background: url("./mods/import.png"); list-style: url("./mods/import.jpg"); @font-face { src:url("./mods/import.ttf"); }