Closed bastiRe closed 8 years ago
Try the opposite– increase the polling interval. You might be overwhelming the watcher.
If you want to use watchify only caching and not watching, you can use the ignoreWatch
option to ignore everything, and then call bundle()
based on some other external event – like from watch-network.
Hey, thanks for the help. I tried to increase the polling interval, but even if I put it to 5 seconds it's taking the watcher more than 10 seconds to register the change, which makes it faster to do a full bundle without watchify.
I also tried to use watchify just for caching (which would be awesome), but it somehow did not register any changes when rebundling. I'm using watchify/browserify through gulp. When the gulp task runs the first time I'm configuring a bundler for each of my configs and then cache it. Each subsequent run only calls bundle on the bundler. Attached is the code, am I missing something?
var cached = {}
_.forEach(config.sources, function (src) {
gulp.task('javascript:' + src.name, function () {
var b = cached[src.name]
if(!b){
b = browserify({
entries: glob.sync(src.javascript.entry),
debug: true,
transform: ['coffeeify', 'babelify', 'hbsfy'],
extensions: ['.coffee', '.hbs'],
paths: ['./gulp/assets/javascripts'],
cache: {},
packageCache: {}
}).on('error', handleErrors)
//enable watching if not in production
if(!argv.production) {
b.plugin(watchify, {ignoreWatch: '**'});
b.on('time', function(time){
util.log(util.colors.green('Browserify'), src.name, util.colors.blue('in ' + time + ' ms'));
});
}
cached[src.name] = b
}
return b.bundle()
.pipe(source(src.name + '.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpIf(argv.production, uglify().on('error', handleErrors)))
.pipe(gulpIf(argv.production, sourcemaps.write(config.maps, {
sourceMappingURLPrefix: ' '
}), sourcemaps.write()))
.pipe(gulp.dest(src.javascript.dest))
})
})
It's not going to register any changes because you have to invalidate the cached file. You can either manipulate the cache
object directly (the keys are absolute file paths), or emit a change
event on the browserify instance with the full file path.
@bastiRe any updates on this?
Hey,
sorry, that I didn't reply earlier. I solved it by manipulating the cache
object, like you suggested. There are still some bugs in my solution but it works 98% of the time.
Ok cool. Feel free to open a new issue if you can narrow down that remaining 2%
I hope this is the right place to post this, if not please correct me:
I'm using browserify to build multiple JS bundles on a Vagrant machine which runs the NFS filesystem. As my builds grew bigger I wanted to start using watchify to keep compile time low. I'm using the
poll
option to get watchify to register changes on the files. However, regardless of how small I make the polling intervall watchify only registers changes around 30 seconds after they happen, which defeats the purpose of watchify. Is this normal?I'm also using https://www.npmjs.com/package/watch-network to register changes in my css and recompile it. Would it be possible to restart watchify through this external watcher?