Using libsass with Rails asset pipeline
Asked Answered
A

1

11

I'm trying to get libsass to work with the Rails 4 asset pipeline. So far I've cloned the ruby-libsass Gem from Github into the Vendor folder of my application. I added the followig to my gemfile:

gem 'sassc', path: 'vendor/ruby-libsass/'

I then followed the docs and added the submodules for libsass. Within the libsass folder I had to clone in the sass2scss library for it to compile. I compiled it with make install-shared which created /usr/local/lib/libsass.so. After this, running rake assets:precompile give the following error:

rake aborted!
LoadError: Could not open library 'sass': dlopen(sass, 5): image not found.
Could not open library 'libsass.dylib': dlopen(libsass.dylib, 5): image not found

So I symlinked libsass.dylib this to /usr/local/lib/libsass.dylib. After that, I received the following error:

NameError: uninitialized constant SassC::Lib::Context::SassOptions

I tried commenting out the line in /ruby-libsass/lib/sassc/lib/context.rb that calls SassOptions, and that seemed to have made it work and compiling the assets. The commented out code on line 20, context.rb:

layout :source_string, :pointer,
  :output_string, :string,
  # :options, SassOptions,
  :error_status, :int,
  :error_message, :string,
  :c_functions, :pointer,
  :included_files, :pointer,
  :num_included_files, :int`

Now, the problem I'm having is that I see no speed difference. It stays at around 7 seconds to compile my assets, with or without adding libsass to my Gemfile. Since the initial compile gave an error relating tot libsass.dylib file not being found, I assumed that it's actually using sassc instead of sass, but it looks like it isn't.

Any ideas what I could be missing? I have no experience with C, so I'm not even sure if I compiled everything correctly, etc.

Aschim answered 1/11, 2014 at 11:2 Comment(4)
this guy had it working in the past, it looks like he had to fork sass-rails: github.com/andrew/libsass-railsDiaphoretic
in context.rb, add the following to the top: require_relative 'sass_options'.Linguini
Thanks I'll give it a go when I have a minute and see if that makes any difference. I think the problem is more that the compiled libraries don't get used.Aschim
Don't know yet. Involved with a startup and don't have a whole lot of time to play around with stuff at the moment. :)Aschim
A
2

Right, I finally got it working thanks to this gem! The project is still a WIP, and can do with a few supporters. :)

Only issue I ran into is that you need to completely remove sass-rails from your project, which can be a problem if you use gems like ActiveAdmin. There are workarounds though. Then, plain css files that get included in your scss files with @import need to have .css at the end of the filename in the import.

Aschim answered 10/4, 2015 at 7:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.