sprockets-rails
sprockets-rails copied to clipboard
Assets with index files not allowed everywhere?
I'm using sprockets with its ability to use index files to organize assets. So with the following file structure under app/assets/stylesheets/foo/:
- index.css.scss
- bar.css.scss
- baz.css.scss
app/assets/stylesheets/foo/index.css.scss looks like this:
/*
*= require some_lib
*= require some_other_lib
*= require_tree .
*= require_self
*/
// alotta styles
// ...
My config/initializers/asset.rb says:
Rails.Application.config.assets.precompile << 'foo.css'
So now on to the actual issue: in Rails 3.2.x this used to compile to
public/assets/foo.css
In Rails 4.2.x with sprockets-rails 2.3.3 it compiles to
public/assets/foo/index.css
This means that all my references a la <%= stylesheet_link_tag 'foo' %> are throwing errors like
Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( foo/index.css )` to `config/initializers/assets.rb` and restart your server
Was this change intentional?
If so, why is there a possibility to use sprockets with index files at all, if you can't actually reference them via helpers like stylesheet_link_tag etc?
Additionally this leads to localhost:3000/assets/foo.css working in development, but not in production.
So: is this a bug or desired behavior?
Regards, Enno
Could you check with sprockets-rails master and sprockets 3?
Trying with sprockets-rails master (and sprockets 3.4.0) gives following behavior:
<%= stylesheet_link_tag 'foo' %> will tell me to place Rails.application.config.assets.precompile += %w( foo.css ) in my initializer. Unfortunately I already did this, but sprockets doesn't seem to recognize.
Additional info:
<%= stylesheet_link_tag 'foo/index' %>works fine, althoughfoo/index.cssis not in precompile array (foo.cssstill is)- precompiling still generates
foo/index-#{digest}.cssinstead offoo-#{digest}.css
So it seems like adding foo.css to the precompile array translates to foo/index.css somewhere in the process, which I think is even weirder. Before (v2.3.3) it was just that foo.css wasn't an option, you were forced to use foo/index.css everywhere (in view helper and precompile array). Now (v3.0.0.beta3) both foo.css or foo/index.css can be used in precompile array, but only foo/index.css is allowed in helpers.
This still seems like a regression to me, since it worked flawlessly with rails 3.2. So my question remains: is this desired behavior or a bug?
Thanks for your time and effort!
I'm experiencing a similar problem when I upgraded sprockets-rails to v2.2.4, during an Rails upgrade from 4.2.0 to 4.2.5.1.
My fix was also similar: I have to precompile the index file foo/index.js and bar/index.js instead, i.e.:
Rails.application.config.assets.precompile += ['foo/index.js', 'bar/index.js']
Not sure if this is intended, but definitely think this should be documented if it is.
But this enforcement of having to write foo/index instead of foo leaves the whole convention of index files useless, unless you use it in a require statement (*= require foo). This difference between require in asset files and stylesheet_link_tag is confusing and probably not intended (I'd guess).