Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Stub causes shared dependency not to be required #467
Consider the following manifests:
//= require jquery //= require_tree . //= stub active_admin
//= require jquery //= require a_bunch_of_other_stuff
Is this behavior intentional? It seems to me that an explicit require at the same level or higher than the stub should override the stub.
The use case was separate manifests (and compiled files) for different areas of the site.
I've solved this now by moving the admin JS out to lib/assets. The other option would be to drop require_tree.
I have the same issue, and I think this is a common requirement. In my application, I want to precompile 3 bundles:
Libraries usually never change and are big, so bundling them altogether won't invalidate their cache usually after each deployment. Client stuff are intended to be available to all users and shouldn't include duplicate dependencies from libraries.js. Finally internal.js is supposed to contain only code relevant to internal users (admin, editors, etc). Since libraries.js and client.js are always included, internal.js shouldn't contain any duplicates from those files.
Currently I'm finding it a headache to try to accomplish this set-up with sprockets, while it's way easier to use the Grails Resources plugin DSL to get the same effect (take a look at defaultBundle):
Right now, just having something like a stub_tree preprocessor would already help a bit, but I'd love to have support for proper bundling from Sprockets. Are there any plans for that in the roadmap?
Back to derekprior's original issue. Stubbing "active_admin" also stubs jquery. I'm having this same problem and cannot figure a good way to stub "active_admin" without stubing jquery. (Note I'm trying to stub "mercury.js" from the Mercury Editor, so I'll call it "mercury" for the rest of this message) "mercury" is loaded on some pages explicitly and application.js is not loaded on those pages because they have a different layout and entirely different functionality. So I need jquery to load with mercury and separately with application. I want to keep require_tree, and exclude mercury from application.js.
Can this be done?
It seems it cannot and stub would make more sense to me if it just excluded what was named, "mercury". And not the requires found in mercury.
It's fine that once a file is stubbed it cannot be included and previous requires/includes are not performed. What's problematic for me is that stub also black lists the requires and includes of the file that was stubbed. Can't it just stub mercury since I wrote "stub mercury.js" instead of also stubbing jquery? In derekprior's case, can't stub just black list "active_admin" since he typed "stub active_admin" instead of also stubbing jquery?
It makes sense that stubbing a file would make sprockets unaware of the original file's dependencies. The contents of the file have been stubbed - it has no
The problem for me comes when I explicitly require something and that required is ignored because a previous stub also happened to require it as a dependency. Stubbing should ignore the listed dependencies in that context only. If the dependencies are required elsewhere then it should work because the dependencies themselves were not explicitly stubbed.
I agree with derekprior.
rosenfeld makes a point that it's also useful to recursively stub (black list) all dependencies of the stubbed file. In this case there are two solutions I can imagine:
Sounds like there's room to grow with this stub command. I think having it mirror require as in point 2 would be best.