Created
April 15, 2015 04:00
-
-
Save alyssaq/165f015956e1750bbde0 to your computer and use it in GitHub Desktop.
Browserify - separate app and enternal vendor bundles from package.json
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 babelify = require('babelify') | |
var browserify = require('browserify') | |
var source = require('vinyl-source-stream') | |
var buffer = require('vinyl-buffer') | |
var globalShim = require('browserify-global-shim').configure({ | |
'm': 'm', | |
'Auth0Lock': 'Auth0Lock', | |
'Papa': 'Papa' | |
}); | |
gulp.task('vendor', function () { | |
let b = browserify({ | |
debug: true, | |
bundleExternal: true | |
}) | |
getNPMPackageIds().forEach(function (id) { | |
b.require(require('resolve').sync(id), { expose: id }); | |
}); | |
return b.bundle() | |
.pipe(source('vendor.js')) | |
.pipe(buffer()) | |
.pipe($.sourcemaps.init({loadMaps: true})) | |
.pipe($.sourcemaps.write('./')) | |
.pipe(gulp.dest('.tmp/vendor')) | |
}) | |
gulp.task('browserify', function() { | |
let b = browserify({ | |
entries: './app/scripts/app.js', | |
debug: true, | |
bundleExternal: false | |
}) | |
getNPMPackageIds().forEach(function(id) { | |
b.external(id) | |
}) | |
return b.transform(babelify) | |
.transform(globalShim) | |
.bundle() | |
.pipe(source('main.js')) | |
.pipe(buffer()) | |
.pipe($.sourcemaps.init({loadMaps: true})) | |
.pipe($.sourcemaps.write('./')) | |
.pipe(gulp.dest('.tmp/scripts')) | |
}) | |
function getNPMPackageIds() { | |
return Object.keys(require('./package.json').dependencies) || []; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment