1

Hi I'm looking to create a common bundle with dependencies shared by multiple pages and a page specific bundle for each page.

I can use this to create the multiple bundles:browserify-multiple-destination

But I need to create the common file with shared dependencies as to avoid duplication.

Is it possible to include factor-bundle to this task in order to separate common dependencies?

Browserify + Globs (multiple destination) Recipe

var gulp = require('gulp');
var browserify = require('browserify');
var gutil = require('gulp-util');
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) {

      gutil.log('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)
    .pipe(buffer())

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

    .pipe(uglify())

    // write sourcemaps
    .pipe(sourcemaps.write('./'))

    .pipe(gulp.dest('dest'));

});
Neatpixels
  • 75
  • 1
  • 9
  • You should put the recipe in your question just in case the link changes – casr Oct 29 '16 at 10:18
  • The answer here might get you most of the way: http://stackoverflow.com/a/23795802/272960 . If you would like to use `watchify` then I think you’ll need to work the problem a bit more. – casr Oct 29 '16 at 18:42

0 Answers0