sprockets icon indicating copy to clipboard operation
sprockets copied to clipboard

Accessing the content of compiled assets in Sprockets 4

Open brendon opened this issue 7 years ago • 6 comments

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 file basics.css file. This no longer works in Sprockets 4. I'm taking this directly from the less-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 enumerate preprocessors and transformers 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.

brendon avatar Jun 14 '17 01:06 brendon

Just wondering if anyone would be able to help with this?

brendon avatar Sep 10 '17 22:09 brendon

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?

schneems avatar Sep 12 '17 15:09 schneems

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.

brendon avatar Sep 12 '17 19:09 brendon

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?

schneems avatar Nov 17 '17 17:11 schneems

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

brendon avatar Nov 27 '17 00:11 brendon

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

brendon avatar Aug 23 '18 23:08 brendon