Nickel Palladium Manganese
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

gulp-browserify-thin

0.1.5 • Public • Published

gulp-browserify-thin

A very thin extension of Browserify that overrides the bundle() method to return a vinyl file object stream instead of the original node readable stream.

Until you call bundle(), you are working with a plain old browserify instance. See Browserify's documentation for option and method documentation.

Installation

$ npm install gulp-browserify-thin --save-dev

Usage

In your gulpfile...

var gulp = require('gulp');
var browserify = require('gulp-browserify-thin');
 
gulp.task('default', function()
{
    // This part is just like using vanilla Browserify.
    var b = browserify(/* files=[] or opts={} */)
        .add(file, opts)
        .require(file, opts)
        .external(file)
        .ignore(file)
        .exclude(file)
        .transform(opts, tr)
        .plugin(plugin, opts)
        // ... and so on, calling browserify methods any way you want.
        ;
 
    // The bundle method is the only one that's different from vanilla
    // Browserify. It takes a filename instead of an optional callback.
    // The filename does not need to exist. It's "fake" so that downstream gulp
    // plugins that expect a filename will still work. It will also be your
    // output filename if you pipe to gulp.dest().
    var stream = b.bundle('output.file.name.js')
 
    // You now have a through object stream that will have a vinyl file
    // pushed into it. The vinyl file contains the filename and the readable
    // stream that Browserify outputs. This is what gulp plugins are
    // expected to return so you can now do your gulp thing!
 
    stream
        // errors emitted by the original Browserify bundle method are
        // re-emitted on the through stream so that they can be handled in your
        // gulp file.
        .on('error', function(err)
        {
            console.error(err.toString());
 
            // If you want to abort the gulp run then you'll need to exit.
            process.exit(1);
        })
        .pipe(/* some other gulp plugin that handles streamed sources */)
        .pipe(gulp.dest('./out'));
 
    // Remember to return the stream when you're done so that any dependant
    // tasks know not to start until this task is done.
    return stream;
});

install

npm i gulp-browserify-thin

Downloadsweekly downloads

49

version

0.1.5

license

MIT

repository

githubgithub

last publish

collaborators

  • avatar