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

查看:27
本文介绍了带有 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" %>;"

虽然,如果我删除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:

  1. scss.erb ruby​​ 代码不是执行
  2. 资产未通过 .erb 运行预处理器
  3. Rails erb 预处理未在开发中进行模式
  4. sprockets sass 部分 erb扩展名.

他们中的一些人最终通过改变方法解决了这个问题.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屋!

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