npm i --save browserify-common-prelude
Better use with factor-bundle ([https://github.com/undoZen/gulp-factor-bundle](gulp plugin)).
// build.js
// ...
var bcp = fs.readFileSync(require.resolve('browserify-common-prelude/dist/bcp.min.js'), 'utf-8');
browserify({
prelude: bcp
})
.require('jquery')
.require('bluebird')
.bundle()
.pipe(fs.createWriteStream('./global.js'));
browserify({
prelude: bcp
})
.require('chart.js')
.require('moment')
.bundle()
.pipe(fs.createWriteStream('./account.js'));
browserify({
prelude: bcp
})
.require('./a.js')
.external(['jquery', 'bluebird'])
.bundle()
.pipe(fs.createWriteStream('./a.bundle.js'));
browserify({
prelude: bcp
})
.require('./b.js')
.external(['jquery', 'bluebird', 'chart.js', 'moment'])
.bundle()
.pipe(fs.createWriteStream('./b.bundle.js'));
<!doctype html>
<!-- a.html - only one common lib, data-common attribute could be omitted -->
<script src="/global.js"></script>
<script src="/a.bundle.js"></script>
<!doctype html>
<!-- b.html - script tags with data-common attribute must be one after another, no other tags in between -->
<script src="/global.js" data-common></script>
<script src="/account.js" data-common></script>
<script src="/b.bundle.js"></script>