Skip to content

Multi-bundle support #146

@cguinnup

Description

@cguinnup

I'd like to propose support for multiple LiveReactload bundles in separate browserify/watchify processes:

Reasoning

I'm developing HTML5 GUIs in a large codebase with a number of internal libraries. Hot-reloading needs to occur quickly for both lib changes and changes to the GUI code itself, but presently watchify is not quick to incrementally build one giant bundle. When we split the code into several smaller bundles, watchify is much quicker to rebundle code changes. Additionally, building the bundles in separate processes allows us to speed up the initial non-incremental build.

I believe this is also a step toward #107 (Support factory-bundle), though multiple-entry support is beyond the scope of my proposal here.

Method

  • Only the entry bundle launches a WebSocket server & receives its messages.
  • On any change, the entry bundle patches and reloads all relevant bundles. It does this through a descending chain of exposed functions (akin to how Browserify resolves modules in external bundles).
  • Lib bundles communicate their changes to the WebSocket server (since isolated in a separate process).
  • Lib bundles expose their patch(), evaluate(), and load() on a global __livereactload_export object. Before assigning to that global, any existing __livereactload_export is assigned to a loader()-scoped variable previousBundle, which creates the descending chain of exposed functions I mentioned above.
  • LiveReactload needs a unique bundleId for each bundle. This also signifies that we're using multi-bundle mode. (Better way to do this? Plugin access to dest filename?)
  • HTML must include bundles in order of their dependency.
  • No changes to the current single-bundle LiveReactload API.

Usage Example

var entryBundle = browserify({entry: ...});
entryBundle.plugin(livereactload, {
  bundleId: "myEntryBundle", port: port});

// in a separate process:
libNBundle.plugin(livereactload, {
  bundleId: "myLibNBundle", port: port, server: false, client: false});

I've been working up to this change with the previous smaller issues. Any suggestions on the API? I'm mostly finished the capability, and making this issue to check whether you wish to integrate these changes. I would rather help maintain this as part of the official LiveReactload, but I respect that it's your call to make.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions