Open domenic opened 11 years ago
Any news on this, or pointers to get me started on a PR? (:
No news really... a PR would be amazing. @thlorenz has some ideas, I know, but I forgot most of them.
The new browserify v2 flow is pretty amenable to this sort of thing, I think, although I'm not 100% sure it exposes the right hooks...
Technically you could pull the entire source of the bundle along with paths from the source maps. mold-source-map and/or convert-source-map would help you with that. Then add routes for each to a server and add script tags that pull'em in.
Of course this only works with the --debug
option.
The other thing that may help is that browserify now has an option to list all files (last advanced option) that are being bundled.
Awesome info @thlorenz! That helps a lot. I'll see what I can do. Thanks!
There's also this b.on('file', ...)
thing, I've never used it but it seems possibly relevant.
@thlorenz any ideas on where in the process we can hook in? It sounds like source map work would be done after the conversion to a string; is there anywhere earlier in the process that you think would work well? (But the source map idea is pretty compelling I think, since it means the source map-creator has already done most of the work for us.)
I've been working on this. So far the most reliable option has been through the source map, but I'll try the new advanced option too.
The file and package events won't fire for browserify's special shims, so you get an incomplete tree of files doing that.
b.on('file'...
may work, but I'm not sure how well it plays with transforms, since you'd need to run them manually if you use the original file content. This btw would also be the case with the 'list all files' approach.
The source map approach may be simpler here since the source map will point you to the exact lines in the bundle to find the source code after all the modifications, including transforms.
Of course the next problem is what the output format should be, given browserify v2's new super-compact thing.
Honestly at this point the best idea I have is a bunch of amd modules, plus a massive require.config
that uses the browserify data to create per-file mappings. Combine this with almond or something and you'd be good to go.
Hopefully someone has a better idea :P
Just a small progress update, i've managed to reliably extract a dependency map (correctly, with transforms that add require
) from browserify thanks to @thlorenz's info on the advanced option.
This is awesome, I'm really excited :D.
Another possibility:
browserify --list
to get a list of all filesexternal()
option to exclude all other filesThis approach has the potential to be faster than using source maps. When used in conjunction with watchify, only the affected single-file bundle would need to be updated when a source file is changed.
Thoughts?
The new pipeline should make things easier.