sprockets
sprockets copied to clipboard
Accessing the content of compiled assets in Sprockets 4
Expected behavior
I'm trying to get the less-rails
test suite passing on Sprockets 4, Rails 5.1. The API changes break things:
- In 3 we could do this:
Dummy::Application.assets['basics'].to_s
to return the content of the filebasics.css
file. This no longer works in Sprockets 4. I'm taking this directly from theless-rails
test suite that I have not written myself. What would be the replacement approach? - In 3 we could enumerate the 'engines' by doing:
Dummy::Application.assets.engines
. This is no longer a method of course. Is there a way to enumeratepreprocessors
andtransformers
etc... in Sprockets 4?
System configuration
- Sprockets version 4.beta4
- Ruby version 2.3.3
Notes
I've added a manifest.js
and tried .find_asset!()
but it still doesn't find the files. The paths listed in the error message don't reflect any changes I make to manifest.js
either.
Just wondering if anyone would be able to help with this?
Do you know why it worked before and why it stopped working?
Did something change in Sprockets or did it change in rails?
Why isn't the asset being found?
Hi @schneems, less-rails
works with Sprockets 3. I'm trying to prepare it for Sprockets 4. I simply changed the Gemfile
to reference it:
gem "sprockets", git: "https://github.com/rails/sprockets.git", branch: "v4.0.0.beta4"
It's been a while, so I haven't tried beta5
but I assume my current problems exist in that too.
I think it's sprockets that has changed since Rails 5.1 with Sprockets 3 works fine.
It's hard to determine if the asset isn't being generated at all, or if the API to find the asset has changed. Also see my second point about enumerating processors etc... Essentially I just want to get the test suite working first so I'd like to know the replacement API for the methods above.
I would recommend making things work with asset_path
first before using find_asset
or the []
alias.
Can you give me a simple example app that works with sprockets 3 but breaks with sprockets 4?
Here's a link to the gem that works with sprockets 2 and 3 but fails with 4. I'm almost 100% sure the files aren't getting produced at all, and thus []
fails to find anything. I've added the default manifest but I was wondering if you could take a quick look and see if I need to add any other config to get it to work again? https://github.com/brendon/less-rails/tree/without-grease-sprockets-4
Just wanted to ping this as we're hoping to get less-rails 4.0.0 released, and adding proper tests for sprockets 4 would be a boon :)