Skip to content

Use with watchify #32

@jbalboni

Description

@jbalboni

We've been using browserify-incremental where I work for a while and I've found that it doesn't work well with watchify. I know there's some overlap there in what this and watchify are supposed to accomplish, but even with the faster compilation between runs, it's nice to have a watch mode that watches the right files and triggers a bundle when they change.

From playing around with watchify, it looks like the issue is that browserify-incremental doesn't emit file events for cached files. I wrote a hackish plugin to change that:

var BrowserifyCache = require('browserify-cache-api');

module.exports = function incrementalWatchPlugin(b) {
    var hasReadCache = false;
    b.on('bundle', function() {
        var cache;
        if (!hasReadCache) {
            cache = BrowserifyCache.getCache(b);
            Object.keys(cache.dependentFiles).forEach(function(file) {
                b.emit('file', file);
            });
            Object.keys(cache.modules).forEach(function(file) {
                b.emit('file', file);
            });
        }
        hasReadCache = true;
    });
};

This seems to work, but it's not super efficient. Watchify still has a cache it doesn't need.

Do you have any thoughts on this? Is there a better way to have a working watch mode? Is there a reason browserify-incremental doesn't emit file events?

browserify-incremental is awesome, by the way. It's the main reason we're still using Browserify; otherwise it'd be too slow for us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions