Jezen Thomas

Jezen Thomas

I'm a programmer and entrepreneur. Occasionally I write about technology, and speak at conferences.

Using Libsass Today

I recently began working on a static site for vaamo. The static site generator we chose is written in Python, so that’s one dependency. We like writing Sass with the old indent syntax, and the original Sass implementation is written in Ruby so that’s another dependency. I love Ruby, but I feel a bit dirty having to depend on it in a Python project.

There is a newer, faster Sass compiler called Libsass, which is written in C/C++. Libsass is a library and doesn’t come with an executable, so we needed some sort of driver to control it with. It seems most people use some flavour of Node.js wrapper, so that’s what I tried first.

I reached for node-sass, which is the most popular Node.js binding for Libsass. This is a simple case of:

On my machine, it worked. Great success. On our TravisCI build server, it exploded with a cryptic message.

This is painful, but not new. Let it be known that npm is a colossal clusterfuck of complexity and it makes me feel like a sad Jimmy Wales. Fortunately, there is a C binary wrapper around Libsass called SassC. It is perhaps slightly less convenient because it needs to be compiled for the machine which consumes it, but I’d rather machines spend a little more time thinking and less time randomly exploding because JavaScript. At a high level, we need to:

  • Pull down both Libsass and SassC
  • Tell the machine where to find the Libsass directory
  • Compile SassC
  • Compile Sass files with the resulting binary

In order to pull down Libsass and SassC, you should have wget installed on your system. If you don’t, you can install it with homebrew.

From your project directory, run the following commands:

You should be left with a binary in the bin directory that you can use to compile your stylesheets.