Last active
August 29, 2015 14:01
-
-
Save mattdesl/ff02f14b8bb45fe10c2b to your computer and use it in GitHub Desktop.
browserify multiple bundles with gulp / vinyl-source-stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = "common utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var common = require('./common'); | |
//... do something with common utils | |
module.exports = "foo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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