使用libsass和Rails资产管道

时间:2021-10-01 09:48:05

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:

我正在尝试让libsass使用Rails 4资产管道。到目前为止,我已经将Github中的ruby-libsass Gem克隆到我的应用程序的Vendor文件夹中。我将followig添加到我的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:

然后我按照文档添加了libsass的子模块。在libsass文件夹中,我不得不在sass2scss库中克隆它以进行编译。我用make install-shared编译了它,它创建了/usr/local/lib/libsass.so。在此之后,运行rake资产:precompile会出现以下错误:

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:

所以我将libsass.dylib符号链接到/usr/local/lib/libsass.dylib。之后,我收到以下错误:

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

NameError:未初始化的常量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:

我尝试在/ruby-libsass/lib/sassc/lib/context.rb中注释掉调用SassOptions的行,这似乎使它工作并编译资产。第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.

现在,我遇到的问题是我看不到速度差异。无论是否将libsass添加到我的Gemfile,它都会在7秒左右的时间内编译我的资产。由于初始编译给出了一个与libsass.dylib文件无关的错误,我认为它实际上是使用sassc而不是sass,但它看起来并非如此。

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.

我有什么想法可以错过吗?我没有使用C的经验,所以我甚至不确定我是否正确编译了所有内容,等等。

1 个解决方案

#1


1  

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

是的,我终于得到了它,感谢这个宝石!该项目仍然是一个WIP,可以与一些支持者。 :)

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.

我遇到的唯一问题是您需要从项目中完全删除sass-rails,如果您使用像ActiveAdmin这样的宝石,这可能是个问题。但是有一些解决方法。然后,使用@import包含在scss文件中的普通css文件需要在导入文件名末尾包含.css。

#1


1  

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

是的,我终于得到了它,感谢这个宝石!该项目仍然是一个WIP,可以与一些支持者。 :)

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.

我遇到的唯一问题是您需要从项目中完全删除sass-rails,如果您使用像ActiveAdmin这样的宝石,这可能是个问题。但是有一些解决方法。然后,使用@import包含在scss文件中的普通css文件需要在导入文件名末尾包含.css。