Reputation: 518
I am trying to configure my application to use browserify with watchify and factor-bundle. However, I seem to either end up with a memory leak or break watchify triggered builds.
My build.js
var browserify = require('browserify'),
watchify = require('watchify'),
fromArgs = require('watchify/bin/args'),
fs = require('fs');
var inputs = [
'./client/src/application.js'
];
var outputs = [
'app/assets/javascripts/bundles/application.js'
];
var commonOutput = 'app/assets/javascripts/bundles/common.js';
var bundle = function(b){
b.plugin('factor-bundle', { outputs: outputs });
b.transform('browserify-shim');
b.bundle().
on('error', function(err) {
console.log(err.toString());
this.emit('end');
}).
pipe(fs.createWriteStream(commonOutput));
};
var watcher = watchify(browserify(watchify.args));
watcher.add(inputs);
watcher.on('update', function(ids) {
bundle(watcher);
console.log('updated with ids:', ids);
});
watcher.on('log', function(msg) {
console.log(msg);
});
bundle(watcher);
With this configuration I get eventually get:
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at WriteStream.EventEmitter.addListener (events.js:160:15)
at Labeled.Readable.pipe (/Users/bmcmullen/dev/whitepages/fouroneone_line/node_modules/factor-bundle/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_readable.js:527:8)
at /Users/bmcmullen/dev/whitepages/fouroneone_line/node_modules/factor-bundle/index.js:73:43
at Array.reduce (native)
at Transform._flush (/Users/bmcmullen/dev/whitepages/fouroneone_line/node_modules/factor-bundle/index.js:65:35)
at Transform.<anonymous> (/Users/bmcmullen/dev/whitepages/fouroneone_line/node_modules/factor-bundle/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
at Transform.g (events.js:180:16)
...
I assume this is because I'm creating that write stream each time and the old ones are not being collected? But I can't figure out the right way to do it.
Upvotes: 4
Views: 459