Browserify + Globs (multiple destination)

This example shows how to set up a task of bundling multiple entry points into multiple destinations using browserify.

The below js task bundles all the .js files under src/ as entry points and writes the results under dest/.

var gulp = require('gulp');
var browserify = require('browserify');
var log = require('gulplog');
var tap = require('gulp-tap');
var buffer = require('gulp-buffer');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');

gulp.task('js', function () {

  return gulp.src('src/**/*.js', {read: false}) // no need of reading file because browserify does.

    // transform file objects using gulp-tap plugin
    .pipe(tap(function (file) {'bundling ' + file.path);

      // replace file contents with browserify's bundle stream
      file.contents = browserify(file.path, {debug: true}).bundle();


    // transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)

    // load and init sourcemaps
    .pipe(sourcemaps.init({loadMaps: true}))


    // write sourcemaps


Last Updated: 8/11/2018, 4:54:05 PM