Is there any way to retrieve dependency tree which browserify uses to build bundle?
Browserify takes a bunch of scripts and makes nice bundle of them, resolving all require dependencies. But I want to see structure of that dependencies.
var scripts = [ 'a.js', 'b.js' ];//a & b require a lot of other scripts
var b = browserify({
entries:scripts
});
b.bundle().pipe(fs.createWriteStream('bundle.js'));
//looking on b in debugger I can't find anything like dependency tree
This code cribbed from the --list
handler in the Browserify bin/cmd.js
script will get you a flat list of files:
// Your setup:
var scripts = [ 'a.js', 'b.js' ]; //a & b require a lot of other scripts
var b = browserify({
entries: scripts
});
// Logging out each of the filenames:
b.pipeline.get('deps').push(require('through2').obj(
function (row, enc, next) {
console.log(row.file || row.id);
next();
}
));
// Bundle as normal:
b.bundle().pipe(fs.createWriteStream('bundle.js'));
(Note: You'll need the through2
package installed for the above to work out of the box.)
A tree can be constructed with the code from the --deps
handler right next to it, but all that code does is spit out a list of JSON blobs, each blob containing a list of other files it depends on; you'll need to build the tree yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With