Skip to content

Abitlity to sort assets within a bundle#344

Closed
jdarais wants to merge 7 commits intomiracle2k:masterfrom
jdarais:master
Closed

Abitlity to sort assets within a bundle#344
jdarais wants to merge 7 commits intomiracle2k:masterfrom
jdarais:master

Conversation

@jdarais
Copy link
Copy Markdown

@jdarais jdarais commented Jul 23, 2014

Hi, I realize you've been working on require.js support, but I also like how Sprockets in the Rails asset pipeline is able to combine js files while taking dependencies into account by looking for a ("//= require <dep.js>") directive in the js file. It's a bit simpler if all you need is the ability to break your js into a file hierarchy and specify dependencies between files.

I implemented this for a small project of mine, and I thought I should share in case you're interested in incorporating it into your own branch. It just adds a new extension point in the bundle code, and the rest is implemented as a sort extension.

Thanks

@miracle2k
Copy link
Copy Markdown
Owner

I like this quite a bit.

Still, there are some thoughts I have:

  • How does this handle caching? During development, if I change my require instructions, it wouldn't pick this up and do a resort, without rebooting the dev server, I believe.
  • This still requires you to list all assets in your Bundle, and then it only ensures the right order; I believe sprockets will just find the files based on the references. If we were to add a "proper" sprockets mode, is there still a need a use-case this approach?

There is #139 for a real sprockets-system (and vaguely #240 might provide inspiration), but thinking about it now, I don't think it easy at all to add this to webassets. How would it interact with the bundle hierarchies (boy do I want to get rid of those)?

This sorting approach may be a good middle ground approach.

@jdarais
Copy link
Copy Markdown
Author

jdarais commented Jul 26, 2014

Yeah, the way this interacts with caching is not great. I'm not too familiar with the caching mechanisms, but it seems that to trigger a re-resolve of the contents list, we would at least need to check timestamps on files and re-resolve if a file has been edited. It would probably be overkill to parse the files each time to find out if the edit involved a dependency change.

On your second point, that's correct that you still need to list all the files in your bundle. In my own project, that's not much of a problem, since my js files are grouped inside of folders, and I can just include the folder names with a glob pattern. (Actually, it would be no problem at all if the resolver supported recursive glob patterns like js/*/.js) The only problem with this approach is that you don't get the benefit of pruning off js files that aren't actually needed. I'm not sure this would be the ideal solution for doing a sprockets-like resolve which finds and includes dependencies in addition to sorting.

I'll see if I can play around with some of these ideas to improve upon the concept.

@miracle2k
Copy link
Copy Markdown
Owner

I would love to have a dependency resolver, but I think webassets needs a redesign for it.

@miracle2k miracle2k closed this May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants