domenic / browserify-deoptimizer

Transforms browserify bundles into a collection of single files
Do What The F*ck You Want To Public License
26 stars 0 forks source link

Work with browserify v2 #3

Open domenic opened 11 years ago

domenic commented 11 years ago

The new pipeline should make things easier.

ben-ng commented 11 years ago

Any news on this, or pointers to get me started on a PR? (:

domenic commented 11 years ago

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...

thlorenz commented 11 years ago

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.

ben-ng commented 11 years ago

Awesome info @thlorenz! That helps a lot. I'll see what I can do. Thanks!

domenic commented 11 years ago

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.)

ben-ng commented 11 years ago

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.

thlorenz commented 11 years ago

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.

domenic commented 11 years ago

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

ben-ng commented 11 years ago

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.

domenic commented 11 years ago

This is awesome, I'm really excited :D.

aldendaniels commented 10 years ago

Another possibility:

  1. Use browserify --list to get a list of all files
  2. Create a separate bundle for each file
  3. For each bundle, use browserify's external() option to exclude all other files

This 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?