browserify / watchify

watch mode for browserify builds
Other
1.79k stars 181 forks source link

Watchify + stream entries? #289

Closed rtsao closed 8 years ago

rtsao commented 8 years ago

Is it possible to use watchify with a stream entry?

In my case, the other dependencies are normal files (that might be updated by the user), but the entry itself (which may also change) is generated programmatically. It would be nice to use a stream rather than write the entry code to file.

zertosh commented 8 years ago

Only -o/--outfile are required, except for a few watchify specific options, all other options get passed to browserify - including - to indicate that you wish to use stdin as an input. So, yes, you can use stream entries.

rtsao commented 8 years ago

What I'm having trouble with is how to update the stream entries. With watchify, everything can be updated by simply writing to the file (because chokidar will watch for changes and cause the update), but with stream entries there's no such file to watch. I've figured out some hacky ways to update them, e.g. overriding b._recorded[n].source where n is the index of the stream entry, but I was wondering if there was a proper way to do this.

I haven't had any luck finding documentation on how to do this. I've read the watchify source but I'm still working through the browserify/module-deps source and figuring out how they work so I apologize if I'm missing something obvious.

zertosh commented 8 years ago

Ah, yeah, that's not going to work. It's not so much a technical problem but an API problem. There's no standard way to notify that a file stream is "done" and then that a new one came it.

rtsao commented 8 years ago

Yeah, the approach I've been attempting is hooking into the browserify pipeline or cache somehow and trying to replace the entry source, then calling .bundle() afterwards.

The actual streaming part is not really important to me and I only used it because it was the only documented way to add an entry file from memory. And browserify just pipes the stream to a concat-stream and uses the resulting buffer, so it might as well just be a string in the first place.

I suppose this isn't really an issue with watchify but rather with browserify itself and being able to replace/force update entries for subsequent bundles.