pather.js
function processRelativePath(cssPath, importCssPath, importCssText) {
        cssPath = cssPath.split('\\');
        importCssPath = importCssPath.split('/');
        var isSibling = importCssPath.length == 1;
        return importCssText.replace(reg, function(css, before, imgPath, after) {
            if (/^http\S/.test(imgPath) || /^\/\S/.test(imgPath) || isSibling) { //绝对路径or同级跳过
                return css;
            }
            imgPath = imgPath.split('/');
            imgPath = getRelativePath(cssPath, importCssPath, imgPath);
            return before + imgPath + after;
        });
    }
function processRelativePath(cssPath, importCssPath, importCssText) {
        cssPath = cssPath.split('\\');
        importCssPath = importCssPath.split('/');
        var isSibling = importCssPath.length == 1;
        return importCssText.replace(reg, function(css, before, imgPath, after) {
            if (/^http\S/.test(imgPath) || /^\/\S/.test(imgPath) || isSibling) { //绝对路径or同级跳过
                return css;
            }
            imgPath = imgPath.split('/');
            imgPath = getRelativePath(cssPath, importCssPath, imgPath);
            return before + imgPath + after;
        });
    }
function processRelativePath ( cssPath , importCssPath , importCssText ) { cssPath = cssPath . split ( '\\' ) ; importCssPath = importCssPath . split ( '/' ) ; var isSibling = importCssPath . length == 1 ; return importCssText . replace ( reg , function ( css , before , imgPath , after ) { if ( / ^http\S / . test ( imgPath ) || / ^\/\S / . test ( imgPath ) || isSibling ) { //绝对路径or同级跳过 return css ; } imgPath = imgPath . split ( '/' ) ; imgPath = getRelativePath ( cssPath , importCssPath , imgPath ) ; return before + imgPath + after ; } ) ; }
process relative image pathes in specified imported css
@param {String} cssPath css absolute file path
@param {String} importCssPath relative imported css file path
@param {String} importCssText contents of the imported css file
process relative image pathes in specified imported css