如何在 Rails 3.1 的 SCSS 文件中使用 @charset 指令和清单

发布于 2024-11-16 16:14:42 字数 253 浏览 6 评论 0原文

我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

jJeQQOZ5 2024-11-23 16:14:42

只需将 @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.

☆獨立☆ 2024-11-23 16:14:42

UPD:另一种方法是添加@charset“UTF-8”;就在链轮评论之后。无论如何,Sprockets 会将其剪下来并插入到页面顶部。

这对我来说非常有用,只需确保您也包含 require_self 即可 - 在我开始之前,我的 application.css 不包含此内容,因此它没有获取我的 @charset = "UTF8";

最终结果看起来像这样——以防万一其他人为此而头撞墙:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require <your other requires go here>
*/
@charset "utf-8";

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.

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:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require <your other requires go here>
*/
@charset "utf-8";
笑,眼淚并存 2024-11-23 16:14:42

纳什的答案可能在某一时刻有效,但对我不起作用。我必须通过在注释中添加 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文