-
Couldn't load subscription status.
- Fork 61
Description
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(), andload()on a global__livereactload_exportobject. Before assigning to that global, any existing__livereactload_exportis assigned to aloader()-scoped variablepreviousBundle, which creates the descending chain of exposed functions I mentioned above. - LiveReactload needs a unique
bundleIdfor 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.