milankinen / livereactload

Live code editing with Browserify and React
MIT License
865 stars 61 forks source link

Multi-bundle support #146

Open cguinnup opened 7 years ago

cguinnup commented 7 years ago

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

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.

milankinen commented 7 years ago

Hi! Just trying to understand the use case:

cguinnup commented 7 years ago

Looking over my initial proposal, I see I didn't clearly state the primary objective. So to clarify...

Primary use case: Scales LiveReactload to large projects, while keeping the ability to hot-reload all library modules. Does so by allowing multiple bundles, which leads to 1) smaller bundles to rebuild on incremental changes (thus quicker) and 2) the ability to use multiple cores on the initial watchify builds.

To answer your questions:

If anything's unclear, let me know.

EugeneZ commented 7 years ago

I also have a project this change would help a lot. I am building multiple Browserify bundles from different repositories, and currently only use LiveReactload in the primary package, so I lose development cycles on the submodules. Looking over @pizza2code's proposal, I believe it would work for me, too, as I can specify a bundleId for my container project, and I can then add LiveReactload to the submodules.

milankinen commented 7 years ago

Hmmm, interesting. I'm definitely interested in this if we manage to get this working properly. 👍

How are the inter-bundle dependencies solved? I.e. when I change something in the bundle x, how does the system know whether or not I need to reload also bundles y and z (and from which modules the reloading should start / which modules from those bundles use the exposed and reloaded functionality of x)?