如何在 Rails 3.1 的 SCSS 文件中使用 @charset 指令和清单
我想使用Rails 3.1中的manifest方法
/*
*= require_self
*= require_tree .
*/
但是,我还需要指定一个编码指令
@charset "UTF-8";
这两个似乎都需要在第一行进行解释,但只有一个可以。因此,要么我得到我的字符集指令,要么我得到链轮清单。
我怎样才能两者兼得?
I want to use the manifest methods in Rails 3.1
/*
*= require_self
*= require_tree .
*/
However, I also need to specify an encoding directive
@charset "UTF-8";
Both of these seem to need to be in the first line to be interpreted, but only one can be. So either I get my charset directive or I get the Sprockets manifest.
How can I get both?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将
@charset "UTF-8";
放在任何不使用 Sprockets require 指令的必需 css/sass 文件中,它将被正确编译到application.css (请参阅 在 CSS 连接中处理 @charset)UPD:另一种方法是添加
@charset "UTF-8";
就在 Sprockets 注释之后。不管怎样,Sprockets 会将其剪下来并插入到页面顶部。Just place
@charset "UTF-8";
in any required css/sass file that doesn't use Sprockets require directive and it will be correctly compiled onto the top of the application.css (see Handle @charset in CSS concatenations)UPD: another approach is to add
@charset "UTF-8";
right after the Sprockets comments. Anyway Sprockets will cut it out and insert at the top of a page.这对我来说非常有用,只需确保您也包含 require_self 即可 - 在我开始之前,我的 application.css 不包含此内容,因此它没有获取我的 @charset = "UTF8";
最终结果看起来像这样——以防万一其他人为此而头撞墙:
This worked great for me, just have to make sure you also include require_self also -- before I started, my application.css didn't include this, so it wasn't picking up my @charset = "UTF8";
The end result ended up looking like this -- just in case anyone else was banging their head against the wall about this:
纳什的答案可能在某一时刻有效,但对我不起作用。我必须通过在注释中添加 utf-8 字符来欺骗 Sprockets 将字符集设置为 utf-8:
来源:
https://github.com/sstephenson/sprockets/issues/220
Nash's answer might have worked at one point but didn't work for me. I had to trick Sprockets into setting charset to utf-8 by adding a utf-8 character in a comment:
Source:
https://github.com/sstephenson/sprockets/issues/220