Skip to content

Instantly share code, notes, and snippets.

@jgarber623
Last active August 29, 2015 14:16
Show Gist options
  • Save jgarber623/39fd42b3468f96458a3a to your computer and use it in GitHub Desktop.
Save jgarber623/39fd42b3468f96458a3a to your computer and use it in GitHub Desktop.
Answering some of @mrmrs_ questions about Rails' Asset Pipeline

I'd like to have an easily modular and configurable build system with proper logs set up. Seems non-trivial.

I'm not totally sure what you have in mind. Can you expand on what you mean by "configurable build system with proper logs"…?

I'd also like visibility into how these includes work and where some of the imported third party stuff actually comes from.

Ah, yes. The Asset Pipeline's load paths situation is a bit of black magic. To my knowledge, there are at least four places a Rails app will look for assets:

  1. In gems (e.g. Compass, Breakpoint, etc.). This is the least obvious since the files you want to include don't appear in the folder structure of your project. You simply include them in, say application.css.scss by doing @import 'breakpoint';.
  2. In lib/assets. I think. I have no idea what might end up in here, but it's a default folder in a fresh Rails app.
  3. In vendor/assets. I believe this is where you would put third-party CSS, JS, etc. (e.g. Normalize.css, jQuery). Libraries, basically.
  4. In app/assets. This is where most of your JS and CSS (SCSS, etc.) files will go. You can create as many subfolders as is practical for your project and include them in application.css.scss with lines like @import fonts; (which maps to app/assets/stylesheets/_fonts.scss), @import base/*; (which includes all SCSS files in app/assets/stylesheets/base/), and @import "components/**/*"; (which includes all SCSS files in app/assets/stylesheets/components/ and any of its subfolders).

I'm not certain of the exact load order, so keep that in mind.

In my experience, I've never put a file or seen a file in lib/assets. Also, I rarely ever put files in vendor/assets.

I've recently started using Rails Assets which is this great service that ad hoc creates gems from Bower packages. For me, it's replaced the need to put anything in vendor/assets. Take a peak at lines 4, 12, and 13 in this Gemfile and line 1 in this SCSS file for an example of how I'm using the service to include Normalize.css.

I would also like them to stop promoting the practice of having a new css partial for every view.

Agreed, that shit's terrible. Delete any of those files as soon as they're created by the generators. 🔥 💀


Hopefuly some of that is helpful. I'm curious to hear what you have in mind for your first comment.

@jgarber623
Copy link
Author

Not trying to convince you to stick with the Asset Pipeline, but doing a little digging I found a couple of things:

  • If you published your various modules to Bower, you could include them with Rails Assets as mentioned earlier.
  • Autoprefixer for Ruby and Ruby on Rails
  • I'm not familiar enough with Rework to know how that might plug in to something like Asset Pipeline.
  • I found some sketchy, dated advice on running linters in Rails but… I don't trust them.

So all that's to say, there are some tools out there but it's clear development on the Asset Pipeline hasn't kept up with the breakneck pace of the front-end tooling scene. I've not yet felt the kind of pain you, @jessicard, and others have felt but there's clearly deficiencies in Asset Pipeline. I very well could be suffering from Stockholm Syndrome having spent so many years working in Rails apps.

I'm anxious to give @jessicard's Gulp replacement a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment