index.js
function (options) {

        var me = this;

        var hashMap = me.hashMap;
        var dependencyMap = me.dependencyMap;

        var filter;
        var replace;

        if (options) {
            filter = options.filter;
            replace = options.replace;
        }

        return me.custom(function (file, callback) {

            if (!filter || !filter(file)) {

                var iterator = getIterator(file);

                if (iterator) {
                    iterator(file, me, {
                        process: function (file, dependencies) {

                            if (replace) {
                                var srcContent = file.contents.toString();
                                var destContent = replace(file, srcContent);
                                if (destContent && destContent !== srcContent) {
                                    file.contents = new Buffer(destContent);
                                }
                            }

                        },
                        rename: function (file, dependency) {

                            var prefix = './';

                            // "./a.js" 重命名为 "./a_123.js"
                            // 但是 path.join('.', 'a.js') 会变成 a.js

                            if (dependency.raw.indexOf(prefix) !== 0) {
                                prefix = '';
                            }

                            var dependencyPath = me.renameDependency(

                                file,
                                me.getFileHash(
                                    file.path,
                                    hashMap,
                                    dependencyMap,
                                    true
                                ),

                                dependency,
                                me.getFileHash(
                                    dependency.absolute,
                                    hashMap,
                                    dependencyMap,
                                    true
                                )

                            );

                            if (prefix && dependencyPath.indexOf(prefix) !== 0) {
                                dependencyPath = prefix + dependencyPath;
                            }

                            return dependencyPath;

                        }
                    });
                }
            }

            callback();

        });

    }
function (options) {

        var me = this;

        var hashMap = me.hashMap;
        var dependencyMap = me.dependencyMap;

        var filter;
        var replace;

        if (options) {
            filter = options.filter;
            replace = options.replace;
        }

        return me.custom(function (file, callback) {

            if (!filter || !filter(file)) {

                var iterator = getIterator(file);

                if (iterator) {
                    iterator(file, me, {
                        process: function (file, dependencies) {

                            if (replace) {
                                var srcContent = file.contents.toString();
                                var destContent = replace(file, srcContent);
                                if (destContent && destContent !== srcContent) {
                                    file.contents = new Buffer(destContent);
                                }
                            }

                        },
                        rename: function (file, dependency) {

                            var prefix = './';

                            // "./a.js" 重命名为 "./a_123.js"
                            // 但是 path.join('.', 'a.js') 会变成 a.js

                            if (dependency.raw.indexOf(prefix) !== 0) {
                                prefix = '';
                            }

                            var dependencyPath = me.renameDependency(

                                file,
                                me.getFileHash(
                                    file.path,
                                    hashMap,
                                    dependencyMap,
                                    true
                                ),

                                dependency,
                                me.getFileHash(
                                    dependency.absolute,
                                    hashMap,
                                    dependencyMap,
                                    true
                                )

                            );

                            if (prefix && dependencyPath.indexOf(prefix) !== 0) {
                                dependencyPath = prefix + dependencyPath;
                            }

                            return dependencyPath;

                        }
                    });
                }
            }

            callback();

        });

    }
function ( options ) { var me = this ; var hashMap = me . hashMap ; var dependencyMap = me . dependencyMap ; var filter ; var replace ; if ( options ) { filter = options . filter ; replace = options . replace ; } return me . custom ( function ( file , callback ) { if ( ! filter || ! filter ( file ) ) { var iterator = getIterator ( file ) ; if ( iterator ) { iterator ( file , me , { process : function ( file , dependencies ) { if ( replace ) { var srcContent = file . contents . toString ( ) ; var destContent = replace ( file , srcContent ) ; if ( destContent && destContent !== srcContent ) { file . contents = new Buffer ( destContent ) ; } } } , rename : function ( file , dependency ) { var prefix = './' ; // "./a.js" 重命名为 "./a_123.js" // 但是 path.join('.', 'a.js') 会变成 a.js if ( dependency . raw . indexOf ( prefix ) !== 0 ) { prefix = '' ; } var dependencyPath = me . renameDependency ( file , me . getFileHash ( file . path , hashMap , dependencyMap , true ) , dependency , me . getFileHash ( dependency . absolute , hashMap , dependencyMap , true ) ) ; if ( prefix && dependencyPath . indexOf ( prefix ) !== 0 ) { dependencyPath = prefix + dependencyPath ; } return dependencyPath ; } } ) ; } } callback ( ) ; } ) ; }
替换依赖

@param {Object} options
@property {Function=} options.filter
@property {Function=} options.replace
替换依赖