Browserify plugin for Generate an extra chunk, which contains common modules shared between entry points.
npm install common-chunk-ify --save
if you have some source files like this
//entry a.js
var c = require("./c");
var a1 = require("./a1");
module.exports = "a";
//entry a1.js
module.exports = "a1";
//entry b.js
var c = require("./c");
module.exports = "b";
//c.js
module.exports = "c";
"use strict";
const browserify = require("browserify");
const gulp = require("gulp");
let b = browserify(["a.js","b.js"])
.plugin("common-chunk-ify",{
map:{
"a.js":"app.js"
,"b.js":"bpp.js"
}
requireName:"mycommon"
commonName:"mycommon.js"
})
b.on("bundle file",bundle=> {
bundle.pipe(gulp.dest("./dist")); // our some other custom stream
// dist/
// app.js (with a,a1)
// bpp.js (with b)
// mycommon.js (with c only)
})
npm install --save-dev
npm test