src/browserify.js
function (destPath, srcPaths, options) {
    let stream,
        b,
        finalPaths = [];
    return new Promise(function (resolve, reject) {
        _.each(srcPaths, function (path) {
            // deal with file globs
            if (glob.hasMagic(path)) {
                glob.sync(path).forEach((p) => {
                    p = utils.scopePaths(p);
                    finalPaths.push(p);
                });
            } else {
                path = utils.scopePaths(path);
                finalPaths.push(path);
            }
        });

        // add required parameters for watchify
        options.cache = {};
        options.packageCache = {};

        options.debug = options.watch;

        b = browserify(options);

        b.transform(envify({
            _: 'purge',
            NODE_ENV: options.env
        }), {global: true});

        // must add each path individual unfortunately.
        finalPaths.forEach(function (path) {
            b.add(path);
        });

        options.ignore.forEach((file) => {
            b.ignore(file);
        });
        options.exclude.forEach((file) => {
            b.exclude(file);
        });

        // require global files
        _.each(options.requires, function (path, id) {
            // options.requires can be an array of strings or an object
            id = typeof id == "string" ? id : path;
            b.require(path, {expose: id});
        });

        if (options.watch) {
            b.plugin(watchify);
            // re-bundle when updated
            b.on('update', function () {
                console.log('file updated!');
                b.bundle();
            });
        }


        b.on('bundle', function (stream) {
            console.log('browserifying bundle...');
            writeBrowserifyBundleStreamToFile(stream, destPath)
                .then(function () {
                    console.log('done browserifying bundle!');
                    resolve();
                })
                .catch(function (e) {
                    console.log('browserifying failed');
                    console.log(e);
                    reject(e);
                });
        });

        stream = b.bundle();

    }.bind(this));
}
function (destPath, srcPaths, options) {
    let stream,
        b,
        finalPaths = [];
    return new Promise(function (resolve, reject) {
        _.each(srcPaths, function (path) {
            // deal with file globs
            if (glob.hasMagic(path)) {
                glob.sync(path).forEach((p) => {
                    p = utils.scopePaths(p);
                    finalPaths.push(p);
                });
            } else {
                path = utils.scopePaths(path);
                finalPaths.push(path);
            }
        });

        // add required parameters for watchify
        options.cache = {};
        options.packageCache = {};

        options.debug = options.watch;

        b = browserify(options);

        b.transform(envify({
            _: 'purge',
            NODE_ENV: options.env
        }), {global: true});

        // must add each path individual unfortunately.
        finalPaths.forEach(function (path) {
            b.add(path);
        });

        options.ignore.forEach((file) => {
            b.ignore(file);
        });
        options.exclude.forEach((file) => {
            b.exclude(file);
        });

        // require global files
        _.each(options.requires, function (path, id) {
            // options.requires can be an array of strings or an object
            id = typeof id == "string" ? id : path;
            b.require(path, {expose: id});
        });

        if (options.watch) {
            b.plugin(watchify);
            // re-bundle when updated
            b.on('update', function () {
                console.log('file updated!');
                b.bundle();
            });
        }


        b.on('bundle', function (stream) {
            console.log('browserifying bundle...');
            writeBrowserifyBundleStreamToFile(stream, destPath)
                .then(function () {
                    console.log('done browserifying bundle!');
                    resolve();
                })
                .catch(function (e) {
                    console.log('browserifying failed');
                    console.log(e);
                    reject(e);
                });
        });

        stream = b.bundle();

    }.bind(this));
}
function ( destPath , srcPaths , options ) { let stream , b , finalPaths = [ ] ; return new Promise ( function ( resolve , reject ) { _ . each ( srcPaths , function ( path ) { // deal with file globs if ( glob . hasMagic ( path ) ) { glob . sync ( path ) . forEach ( ( p ) => { p = utils . scopePaths ( p ) ; finalPaths . push ( p ) ; } ) ; } else { path = utils . scopePaths ( path ) ; finalPaths . push ( path ) ; } } ) ; // add required parameters for watchify options . cache = { } ; options . packageCache = { } ; options . debug = options . watch ; b = browserify ( options ) ; b . transform ( envify ( { _ : 'purge' , NODE_ENV : options . env } ) , { global : true } ) ; // must add each path individual unfortunately. finalPaths . forEach ( function ( path ) { b . add ( path ) ; } ) ; options . ignore . forEach ( ( file ) => { b . ignore ( file ) ; } ) ; options . exclude . forEach ( ( file ) => { b . exclude ( file ) ; } ) ; // require global files _ . each ( options . requires , function ( path , id ) { // options.requires can be an array of strings or an object id = typeof id == "string" ? id : path ; b . require ( path , { expose : id } ) ; } ) ; if ( options . watch ) { b . plugin ( watchify ) ; // re-bundle when updated b . on ( 'update' , function ( ) { console . log ( 'file updated!' ) ; b . bundle ( ) ; } ) ; } b . on ( 'bundle' , function ( stream ) { console . log ( 'browserifying bundle...' ) ; writeBrowserifyBundleStreamToFile ( stream , destPath ) . then ( function ( ) { console . log ( 'done browserifying bundle!' ) ; resolve ( ) ; } ) . catch ( function ( e ) { console . log ( 'browserifying failed' ) ; console . log ( e ) ; reject ( e ) ; } ) ; } ) ; stream = b . bundle ( ) ; } . bind ( this ) ) ; }
Browserifies a single file bundle.
@param destPath
@param srcPaths
@param options
@param {Object|Array} [options.requires] - Required files
@returns {Promise}
Browserifies a single file bundle .