带有erb的Sass无法编译 [英] Sass with erb won't compile

查看:64
本文介绍了带有erb的Sass无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails中,文件file.css.sass.erb:

In Rails, file file.css.sass.erb:

.class-name
    width: <%= "10px" %>

抛出错误:

Invalid CSS after "": expected expression (e.g. 1px, bold), was "<%= "10px" %>"

这不行吗?

它仍然在挣扎,但是我发现,如果将其更改为SCSS语法(文件名和代码),仍然会导致非常类似的错误.

Still struggling with it, but I found that if I change it to SCSS syntax (filename and code), still it causes a very similar error.

Invalid CSS after " width: ": expected expression (e.g. 1px, bold), was "<%= "10px" %>;"

尽管,如果我 删除 扩展名,而CSS语法类似于文件名file.css.erb,则Rails会按预期进行编译.

Although, if I remove the scss extension, leaving the CSS similar syntax with the filename file.css.erb, Rails does compile as expected.

但是考虑到我忘记了一些非常明显的东西,我也在考虑这可能是与sass-rails的宝石冲突,错误或其他问题. 毕竟,代码在没有SASS扩展名的情况下仍能正常工作.

Yet considering I'm forgetting something very obvious, I'm also considering this could be a gem conflict with sass-rails, or a bug, or something. After all, the code is working without SASS extensions.

在以下同一问题上发现了其他4个未回答的问题:

Just found other 4 unanswered questions on this same issue on:

  1. scss.erb红宝石代码不 执行
  2. 资产无法通过.erb运行 预处理器
  3. 在开发中未进行过erb预处理的轨道 模式
  4. 链轮sass部分erb 扩展名.
  1. scss.erb ruby code not executing
  2. Assets not being run though the .erb preprocessor
  3. Rails erb preprocessing not happening in development mode
  4. sprockets sass partial erb extension.

其中一些最终通过更改方法来解决该问题. SASS文件上的ERB问题保持不变.

Some of them ended up working around the problem by changing approaches. The ERB issue on SASS files remained untouched.

推荐答案

这确实是sass-rails的问题,如所以这家伙写了此补丁,可以完全解决该问题.

So this guy wrote this patch, which completely solves the problem.

添加到Gemfile:

gem "sass_rails_patch", "~> 0.0.1"

然后运行bundle,您就很好了!

then run bundle and you're good!

这篇关于带有erb的Sass无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆