最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use glob matching, when passing files to browserify in gulp - Stack Overflow

programmeradmin4浏览0评论

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

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
Share Improve this question asked Feb 6, 2015 at 18:56 mrwoostermrwooster 24.2k12 gold badges40 silver badges48 bronze badges 3
  • 1 You typically use one file as the entry point, then browserify builds the dependency graph and adds all the necessary files. Do you have an entire directory of browserify entry points? – Ben Commented Feb 6, 2015 at 21:28
  • Yes, I have multiple entrypoints for browserify – mrwooster Commented Feb 6, 2015 at 21:31
  • consider using require-globify – chatoo2412 Commented Apr 25, 2016 at 2:23
Add a comment  | 

1 Answer 1

Reset to default 22

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('.'));
});
发布评论

评论列表(0)

  1. 暂无评论