index.js
function renameDependencies(file, dependencies, rename) {

    var srcContent = file.contents.toString();
    var destContent = srcContent;

    // 按 match 分组
    var group = { };

    dependencies.forEach(function (dependency) {

        var list = group[ dependency.match ];
        if (!list) {
            list = group[ dependency.match ] = [ ];
        }

        list.push(dependency);

    });

    util.each(group, function (dependencies, match) {

        destContent = replaceByPattern(
            destContent,
            match,
            function (result) {

                dependencies.forEach(function (dependency) {

                    var replacement = rename(dependency);
                    if (replacement) {
                        result = replaceByPattern(
                            result,
                            dependency.raw,
                            replacement
                        );
                    }

                });

                return result;

            }
        );

    });

    if (srcContent !== destContent) {
        file.contents = new Buffer(destContent);
    }

}
function renameDependencies(file, dependencies, rename) {

    var srcContent = file.contents.toString();
    var destContent = srcContent;

    // 按 match 分组
    var group = { };

    dependencies.forEach(function (dependency) {

        var list = group[ dependency.match ];
        if (!list) {
            list = group[ dependency.match ] = [ ];
        }

        list.push(dependency);

    });

    util.each(group, function (dependencies, match) {

        destContent = replaceByPattern(
            destContent,
            match,
            function (result) {

                dependencies.forEach(function (dependency) {

                    var replacement = rename(dependency);
                    if (replacement) {
                        result = replaceByPattern(
                            result,
                            dependency.raw,
                            replacement
                        );
                    }

                });

                return result;

            }
        );

    });

    if (srcContent !== destContent) {
        file.contents = new Buffer(destContent);
    }

}
替换依赖

@inner
@param {Object} file
@param {Array} dependencies
@param {Function} rename