node.js - How can I use factor-bundle with browserify programmatically? -


i want use factor-bundle find common dependencies browserify entry points , save them out single common bundle:

https://www.npmjs.org/package/factor-bundle

the factor-bundle documentation makes seem easy on command line, want programmatically , i'm struggling head around it.

my current script (i'm using reactify transform react's jsx files too):

var browserify = require('browserify'); var factor = require('factor-bundle') var glob = require('glob');  glob('static/js/'/**/*.{js,jsx}', function (err, files) {        var bundle = browserify({     debug: true   });    files.foreach(function(f) {     bundle.add('./' + f);   });   bundle.transform(require('reactify'));    // factor-bundle code goes here?    var dest = fs.createwritestream('./static/js/build/common.js');   var stream = bundle.bundle().pipe(dest); }); 

i'm trying figure out how use factor-bundle plugin, , specify desired output file each of input files (ie each entry in files)

this answer pretty late, it's you've either found solution or work around question. i'm answering it's quite similar my question.

i able working using factor-bundle browserify plugin. haven't tested specific code, pattern should same:

var fs = require('fs'),     browserify = require('browserify'),     factor = require('factor-bundle');  var bundle = browserify({     entries: ['x.js', 'y.js', 'z.js'],     debug: true });  // group common dependencies // -o outputs entry files without common dependencies bundle.plugin('factor-bundle', {     o: ['./static/js/build/x.js',          './static/js/build/y.js',          './static/js/build/z.js'] });  // create write stream var dest = fs.createwritestream('./static/js/build/common.js');  // bundle var stream = bundle.bundle().pipe(dest); 

the factor-bundle plugin takes output options o need have same indexes entry files.

unfortunately, haven't figured out how else these files after point because can't seem access factor-bundle's stream event. minification etc, might need done via browserify plugin.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -