RoR - 将多个资产组合到一个文件中

时间:2013-12-15 20:31:28

标签: ruby-on-rails ruby ruby-on-rails-4

如何将app / assets / stylesheets中的多个CSS文件合并到一个application.css.scss中?根据我一直关注的书,我想将所有其他样式表引用到application.css.scss注释部分。但是,它并没有告诉我如何引用每个样式表。

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * 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 .
 */

我知道我必须使用*= require_something,但不确定具体如何。我创建了一个名为custom.css.scss的样式表,并在注释中放置了* = require_custom,但这不起作用。

2 个答案:

答案 0 :(得分:0)

require_tree .指令应足以加载app/assets/stylesheets中包含的任何其他样式表。但是,在应用程序启动时始终会加载静态资产 - 您是否尝试重新启动服务器?

答案 1 :(得分:0)

require_tree .已经要求在同一文件夹或子文件夹中使用所有单独的样式表。

如果你想要包含一些特定的样式表(比如something.css.scss),你可以这样做:

*= include something

但是,如果您在SASS文件中使用要在不同文件中使用的变量,则注释样式包括不起作用。您需要单独导入每个文件:

@import 'something';