Grunt and Rails

614 views Asked by At

I'm working on using a Grunt workflow to manage my assets in my Rails app rather than Sprockets.

So far, I have my apps JS and CSS both being concatenated and minified into public/assets/javascripts/application.js and public/assets/stylesheets/application.css respectively.

And also have my Bower components JS and CSS being concatenated and minified into public/assets/javascripts/vendor.js and public/assets/stylesheets/vendor.css respectively.

Fonts and Images from Bower components are then copied into public/assets/(images|fonts).

This is all well and good but now I need the references to fonts/images within those files to be updated to reflect their new location.

I have looked at cssmin and yes it rewrites file references but I cannot get the file path to change depending upon the type of file being referenced.

Any ideas on how I can do this?

Also, I ahve been reading about Grunt plugins which can read your view files and use those to minify and concatenate files and update the and tags in the views for you.

Surely I can't do that in a Rails app? Is there a way I can deal with this in Rails?

1

There are 1 answers

3
Greg Burghardt On

This other StackOverflow post may be of help:

Integrate Grunt into Rails asset pipeline

The accepted answer recommends using the Half Pipe gem.

The second answer linked to a blog post about a Do-It Yourself solution: Goodbye, Sprockets! A Grunt-based Rails Asset Pipeline.

I haven't used either solution, but they are worth a try.