browserify-deoptimizer icon indicating copy to clipboard operation
browserify-deoptimizer copied to clipboard

Work with browserify v2

Open domenic opened this issue 13 years ago • 11 comments

The new pipeline should make things easier.

domenic avatar Apr 09 '13 20:04 domenic

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

ben-ng avatar Aug 13 '13 01:08 ben-ng

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

domenic avatar Aug 14 '13 01:08 domenic

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.

thlorenz avatar Aug 14 '13 01:08 thlorenz

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

ben-ng avatar Aug 14 '13 02:08 ben-ng

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

domenic avatar Aug 14 '13 02:08 domenic

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.

ben-ng avatar Aug 14 '13 02:08 ben-ng

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.

thlorenz avatar Aug 14 '13 02:08 thlorenz

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

domenic avatar Aug 14 '13 02:08 domenic

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.

ben-ng avatar Aug 14 '13 22:08 ben-ng

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

domenic avatar Aug 14 '13 22:08 domenic

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?

aldendaniels avatar Aug 04 '14 11:08 aldendaniels