开发者

How do I use both a @charset directive and manifests in SCSS files in Rails 3.1

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 b开发者_StackOverflow社区e 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?


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.


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";


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜