带有 erb 的 Sass 无法编译 [英] Sass with erb won't compile
问题描述
在 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" %>;"
虽然,如果我删除scss
扩展名,那么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
的 gem 冲突,或者是一个错误,或者其他什么.毕竟,代码在没有 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:
他们中的一些人最终通过改变方法解决了这个问题.SASS 文件上的 ERB 问题仍未解决.
Some of them ended up working around the problem by changing approaches. The ERB issue on SASS files remained untouched.
推荐答案
这确实是 sass-rails
的问题,正如讨论的 在 GitHub 上.
This is indeed a problem with sass-rails
, as discussed on GitHub.
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屋!