Count the total number of modules in a Browserify bundle.
npm install -g browserify-count-modules
browserify path/to/module/root | bcm
This will output the total number of modules as an integer.
Let's say you have three JavaScript files:
// a.js moduleexports = 'a'// b.js moduleexports = 'b'// index.js moduleexports = + Now count the modules:
$ browserify ./index.js | bcm
3
In this example, there are three modules: index.js, a.js, b.js.
Note that "modules" includes both first-party and third-party modules. So for instance, if you have one npm dependency,
and that dependency has 5 modules, then its 5 modules will be added to your total module count. This also applies to
implicit Browserify dependencies, such as Buffer (which resolves to feross/buffer).
This tool correctly handles --standalone, factor-bundle, bundle-collapser, and minified bundles as well.
Just pass in any Browserify bundle and it'll work.
If you are able to browserify --full-paths, then you can use --verbose
to get a full list of modules in the bundle:
browserify --full-paths path/to/module/root | bcm --verbose
This prints out something like:
Total number of modules: 3 Modules: - /Users/me/project/a.js - /Users/me/project/b.js - /Users/me/project/index.js Note that this only works with --full-paths.
Via the JavaScript API, you can get the total count of modules for a given JavaScript bundle by passing it in as a string. The count you get back will be an integer.
var browserifyCountModules = var jsFile = You can also get the list of dedup'ed and sorted modules by passing in {verbose: true}:
var browserifyCountModules = var jsFile =