watchify, with some bonus features.
watchify
does some great stuff. uber-watchify
takes it one step further. For big bundles,
with lots of transforms, the bundling takes a long time (with jQuery and tranforms we are talking around
30 seconds). If you have incorporated watchify into your build system, and have it run on every start up,
this can be costly. Watchify already uses browserify's internal cache, but it only does so in memory. uber-watchify
attempts to solve this problem by persisting the cache to disk.
- Load/Write a cache file
accept a new option to load/write a pre-existing cache file, namely, cacheFile
. Therefore, first builds run off the cache, as
well as subsequent ones. Provide a method w.write()
, which at the user's discretion, will write out the cache to disk.
- Add an explicit
watch
option
original watchify always watches. If you don't want to write a separate task, and also use uber-watchify for just regular build commands, you can turn off the watching so the process exits.
- If nothing changed, do nothing.
If you start a build, kill the process, and restart it while nothing in browserify has changed, don't do anything.
w.bundle()
will now check all the modification times of the files you are bundling. If nothing has changed, w.bundle()
will
simply return null
.
var cacheFile = path.resolve(__dirname, 'browserify/benbria.cache.json');
var w = watchify(browserify({
cache: watchify.getCache(cacheFile),
packageCache: {},
fullPaths: true,
entries: [path.resolve(__dirname, 'browserify/benbria.coffee')],
extensions: ['.js']
}), {
cacheFile: cacheFile
});
then to watch:
var bundle = function() {
var stream = w.bundle();
if (!stream) {
return;
}
stream
.pipe(source('bundle.js'))
.pipe(gulp.dest('browserify'))
.on('end', function() {
w.write();
});
};
w.on('update', bundle);
bundle();
A full path to the cache file you wish to save to. It will be created if it doesn't exist
Whether to setup watch listeners. Defaults to true
convenience method to load a json
cache file, and if it doesn't exist will give you a blank object.
Pass this to browserify's cache
option.
write out the cache to the specified cacheFile
. Generally you do this once your transform stream gets its end
event.
same as before, but will now return null
if the cache is still valid. (a new cache is invalid)
A full path to the cache file you wish to save to. It will be created if it doesn't exist
Whether to setup watch listeners. Defaults to true
>uber-watchify main.js --no-watch --cache-file main.browserify.cache.json -o bundle.js
MIT