Last Updated: February 25, 2016
·
1.294K
· kiddj2015

Sass Globbing

A few days ago I discovered the true power of Sass. It turns out I really don't need to include every single partial in my main sass file I use. Yes, and neither do you.

There's this fancy gem called 'sass-globbing' and will allow you to do quite awesome things. It's also maintained by Chris Eppstein who is currently on the Sass team. The sass-globbing gem is stable and works very well.

So, on to how it actually works.

Remember how you had to import every partial in a main file that you would use to be compiled into one? Well, this wouldn't be the case if you use sass-globbing.

@import "mixins/gradient";

@import "mixins/button";

@import "components/buttons";

@import "components/forms";

@import "layout/home";

@import "layout/login";

When you do this, it becomes very large and sometimes unreadable for some developers. It will be a hassle to maintain a big file like this in big projects. With sass-globbing you can import an entire folder.

// Import a folder of files.

@import "mixins/*";

@import "components/*";

Note: If you are using Rails 3.1 and up, sass-globbing is built into rails, or I think it might be the sass-rails gem. The point is, you won't need to add this gem.

Installation:
gem install sass-globbing