Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use glob matching, when passing files to browserify in gulp

All the examples I have seen using browserify and gulp assume that you only want to browserify 1 file. This is usually not the case.

I came across an example that used vinyl-transforms, but I am unable to get it to work correctly. Here is the (coffee-script) code:

# Browserify JS

gulp.task 'browserify', [], ->

    # Create the transform
    br = transform (f) ->
        return browserify(f).bundle()

    # Run browserify
    gulp.src(['./public/js/**/*.js'])
        .pipe(br)
        .pipe(gulp.dest('.'))

But I get the following error:

[10:50:55] Starting 'browserify'...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
like image 240
mrwooster Avatar asked Feb 06 '15 18:02

mrwooster


1 Answers

The easiest way would be to use glob directly:

var glob = require('glob');

gulp.task('browserify', function() {
  var files = glob.sync('./public/js/**/*.js');
  return browserify({entries: files})
    .bundle()
    .pipe(gulp.dest('.'));
});
like image 171
Ben Avatar answered Nov 10 '22 08:11

Ben