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



我想在Rails 3.1 中使用manifest方法

 /*
  *= require_self
  *= require_tree .
  */

然而,我还需要指定一个编码指令

 @charset "UTF-8";

这两个似乎都需要在第一行中进行解释,但只有一个可以。所以要么我得到我的charset指令,要么我得到Sprockets清单。

我怎样才能两者都得到?

只需将@charset "UTF-8";放在任何不使用Sprocketsrequire指令的必需css/sass文件中,它就会被正确编译到应用程序的顶部。css(请参阅css串联中的Handle@charset)

UPD:另一种方法是在Sprockets注释之后添加@charset "UTF-8";。无论如何,Sprockets会把它剪下来,插入页面顶部。

UPD:另一种方法是添加@charset"UTF-8";就在Sprockets评论之后。无论如何,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";

Nash的答案可能在某一点上有效,但对我不起作用。我不得不在评论中添加一个utf-8字符,诱使Sprockets将字符集设置为utf-8:

// é

来源:https://github.com/sstephenson/sprockets/issues/220

最新更新