我正在尝试将我的应用程序配置为使用带有watchify和factor-bundle的browserify。但是,我似乎最终导致内存泄漏或破坏了watchify触发的构建。
我的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);
通过这种配置,我最终得到:
(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)
...
我认为这是因为我每次创建写入流并且没有收集旧的写入流?但我无法找到正确的方法。