Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active August 29, 2015 14:01
Show Gist options
  • Save mattdesl/ff02f14b8bb45fe10c2b to your computer and use it in GitHub Desktop.
Save mattdesl/ff02f14b8bb45fe10c2b to your computer and use it in GitHub Desktop.
browserify multiple bundles with gulp / vinyl-source-stream
module.exports = "common utils";
var common = require('./common');
//... do something with common utils
module.exports = "foo";
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
gulp.task('browserify-common', function() {
var bundleStream = browserify('./common.js')
.require('./common.js') //allows you to require('./common')
.bundle();
bundleStream
.pipe(source('./common.js'))
.pipe(gulp.dest('./bin'));
})
gulp.task('browserify-main', function() {
var bundleStream = browserify('./index.js')
.external('./common.js') //don't bundle in the common libs
//.. add more external libs if necessary
.bundle()
bundleStream
.pipe(source('./index.js'))
.pipe(gulp.dest('./bin'))
})
//our entry point...
var foo = require('./foo');
var common = require('./common');
console.log("foo", foo);
console.log("common", common);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment