After a lot of trial-and-error, and after abandoning the gulp-browserify
plugin (it's black-listed, but examples of using browserify
directly in gulp are hard to come by), I managed to get this working. The salient parts of my gulpfile.js
are (I'm not sure at all what the source
calls do):
var gulp = require('gulp'),
gutil = require('gulp-util'),
clean = require('gulp-rimraf'),
rename = require('gulp-rename'),
source = require('vinyl-source-stream'),
browserify = require('browserify');
gulp.task('browserify:externals', function () {
var vendor = browserify(['jquery', 'es5-shim', 'lodash']);
vendor.require('jquery');
vendor.require('lodash', {expose: '_'});
vendor.require('es5-shim');
return vendor.bundle()
.pipe(source("not-used-but-needed-string.js"))
.pipe(rename('external.js'))
.pipe(gulp.dest('./dist'))
.on('error', gutil.log);
});
gulp.task('browserify', ['browserify:externals'], function () {
var app = browserify('./index.js');
app.external('jquery');
app.external('es5-shim');
app.require('./index.js', {expose: 'maxby'});
return app.bundle()
.pipe(source("not-used-but-needed-string.js"))
.pipe(rename('maxby.js'))
.pipe(gulp.dest('./dist'))
.on('error', gutil.log);
});
I've also created a repository with a complete, but minimal example (I'm quite new at this so any corrections are much appreciated).