use browserify cli to do this...

This commit is contained in:
Jared Allard
2015-08-19 15:59:26 -07:00
parent 78ca929350
commit af42599a15
+7 -22
View File
@@ -23,8 +23,8 @@
*
**/
var mdeps = require("module-deps"),
insertGlobals = require('insert-module-globals'),
path = require("path"),
spawn = require('child_process').spawn,
fs = require("fs"),
through = require("through"),
async = require("async"),
@@ -40,30 +40,15 @@ _log = require("./log");
* @param {function} complete - next function to call (async)
**/
function bundle (input, nc, complete) {
var igv = '__filename,__dirname';
insertGlobalVars = igv.split(',').reduce(function (vars, x) { // borrowed from browserify
vars[x] = insertGlobals.vars[x];
return vars;
}, {});
var b = browserify(input, {
builtins: false,
commondir:false,
detectGlobals: false,
insertGlobals: '__filename,__dirname',
insertGlobalVars: insertGlobalVars,
browserField: false
});
var bundlePath = path.join(nc, "lib", "nexe.js");
var ws = fs.createWriteStream(bundlePath);
var proc = spawn('node', ['node_modules/browserify/bin/cmd.js', '--node', input ]);
/*if(fs.existsSync(bundlePath)) {
fs.unlinkSync(bundlePath);
}*/
proc.stdout.pipe(ws);
var bfs = b.bundle(); // open the bundle stream.
bfs.pipe(ws); // pipe it to the write stream we created earlier
proc.on('close', function(code) {
console.log("browserify finished")
})
ws.on('error', function(err) {
console.log(err);
@@ -75,7 +60,7 @@ function bundle (input, nc, complete) {
fs.writeFileSync(bundlePath, source, 'utf8');
complete();
})
});
}
module.exports = bundle;