Rails 3.1/Compass/sprockets - 生成 css 两次

发布于 2024-11-16 10:17:59 字数 1204 浏览 5 评论 0原文

使用compass Rails31分支和sass-rails的github版本:

gem "sass-rails", :git => "https://github.com/rails/sass-rails.git"
gem "compass", :git => "https://github.com/chriseppstein/compass.git", :branch => "rails31"

我创建了一个部分(_base.css.scss),其中包含blueprint/reset和blueprint-typography的导入。我还有一个 screen.css.scss 文件,其中包含我的基本部分。

当 Rails 将其编译为 application.css 时,我看到重置和排版 css 两次。

stylesheets/application.css.scss

/*
 * 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_tree .
*/

stylesheets/partials/_base.css.scss

@import "blueprint/reset";
@import "blueprint/typography";

@include blueprint-typography;

stylesheets/partials/screen.css.scss

@import "partials/_base";

#container { @include container; }

我不太明白这里发生了什么,以及开始使用带有 Rails 3.1 的指南针的正确配置是什么

非常感谢您的指导!

Using the github versions of the compass rails31 branch and sass-rails:

gem "sass-rails", :git => "https://github.com/rails/sass-rails.git"
gem "compass", :git => "https://github.com/chriseppstein/compass.git", :branch => "rails31"

I have created a partial (_base.css.scss) that contains the imports for blueprint/reset and blueprint-typography. I have also a screen.css.scss file that includes my base partial.

When rails compiles this into application.css, I'm seeing my reset and typography css twice.

stylesheets/application.css.scss

/*
 * 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_tree .
*/

stylesheets/partials/_base.css.scss

@import "blueprint/reset";
@import "blueprint/typography";

@include blueprint-typography;

stylesheets/partials/screen.css.scss

@import "partials/_base";

#container { @include container; }

I don't really understand what is going on here, and what is the correct configuration to start using compass with rails 3.1

Thanks a lot for your guideline!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

第七度阳光i 2024-11-23 10:17:59

如果您在 application.css 清单中使用

require_tree .

,它将自动包含包含此文件的目录中的所有文件。

在 application.css 清单中尝试以下方法,而不是使用 @import:

/*
  *= require blueprint/src/reset
  *= require blueprint/src/typography 
  *= require_self
  *= require_tree . 
*/

另外,您可能希望将蓝图放在供应商/资产/样式表中,而不是应用程序/供应商(其中应包含应用程序特定的代码)

If you are using

require_tree .

in your application.css manifest it will automaticaly include all files within directory containing this file.

Try the following method in application.css manifest instead of using @import:

/*
  *= require blueprint/src/reset
  *= require blueprint/src/typography 
  *= require_self
  *= require_tree . 
*/

Also, you may want to put blueprint in vendor/assets/stylesheets instead of app/vendor (which should contain application specific code)

莫相离 2024-11-23 10:17:59

这是我的解决方案,它可能不是应该这样做的方式,(我真的不知道如何使用链轮)但它似乎有效......请让我知道是否有更好的方法来实现这一点。

application.css.scss

/*
 * 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_tree .
*/

@import "blueprint/reset";
@import "blueprint/typography";

@include blueprint-typography;

screen.css.scss

@import "blueprint";
@import "partials/_base";

#container { @include container; }

_base.css.scss

# Columns or colors variables goes here...

Here is my solution, it's maybe not the way It should be done, (I really don't know how to use sprockets) but it seems to work... Please let me know if there is a better way to achieve this.

application.css.scss

/*
 * 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_tree .
*/

@import "blueprint/reset";
@import "blueprint/typography";

@include blueprint-typography;

screen.css.scss

@import "blueprint";
@import "partials/_base";

#container { @include container; }

_base.css.scss

# Columns or colors variables goes here...
美男兮 2024-11-23 10:17:59

这可能不是您的情况,但 css 加载两次的原因之一是您在 @import 语句中添加了文件扩展名(例如 .css)。

This may not be your case, but one reason why a css gets loaded twice is if you put a file extension (e.g., .css) in your @import statement.

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