Open nickdima opened 10 years ago
Hello, anybody have a solution to the question above? I know it's very old, but I am now starting to use factor-bundle, and I am facing the same situation.
Factor Bundle has the ability to run a custom filter via the threshold
option. So you could do:
#!/usr/bin/env node
var browserify = require('browserify')
var fs = require('fs')
var path = require('path')
var entries = [
path.join(__dirname, 'index.js')
]
var outputFiles = [
path.join(__dirname, 'dist-main.js')
]
var b = browserify(entries)
b.plugin('factor-bundle', {
output: outputFiles,
threshold: function (row, groups) {
// Get a relative directory to where we are building
var rPath = path.relative(__dirname, row.file)
// Assuming our node_modules folder is in the same directory that we are
// building in then just declare vendor files as those presiding in it
return !!rPath.match(/^node_modules\//)
}
})
b.bundle().pipe(fs.createWriteStream(path.join(__dirname, 'dist-vendor.js')))
I've made a simple repository showing it all together.
In my project I'm using both npm modules and bower components (with debowerify) which I want to bundle together as
vendor.js
while keeping my own code in anapp.js
bundle.What I did so far is created the
app.js
bundle by settingexternal
to the npm modules and bower components. To figure out what modules to set asexternal
I read the dependencies frompackage.json
andbower.json
.Now, in a similar fashion I would like to parse my codebase, see which requires are external modules and bundle them together. How could I do this?