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

时间:2022-02-25 23:33:49

How can I combine multiple CSS files within app/assets/stylesheets into a single application.css.scss? According to the book I've been following, I'm suppose to reference all other stylesheets into the application.css.scss comment section. However, it didn't tell me how I can refer to each stylesheet.

如何将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 .
 */

I know I have to use *= require_something but not sure exactly how. I've created a stylesheet called custom.css.scss and placed *=require_custom within the comment but this didn't work.

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

2 个解决方案

#1


0  

The require_tree . directive should be sufficient to load any additional stylesheets contained within app/assets/stylesheets. However, static assets are always loaded when the app is spun up – have you tried restarting your server?

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

#2


0  

require_tree . already requires all the separate stylesheets in the same folder or subfolders.

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

If you want to include some specific stylesheet (say something.css.scss), you can do:

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

*= include something

However if you use variables in your SASS files which you want to use across different files, the comment style includes don't work. You'd need to import each file separately:

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

@import 'something';

#1


0  

The require_tree . directive should be sufficient to load any additional stylesheets contained within app/assets/stylesheets. However, static assets are always loaded when the app is spun up – have you tried restarting your server?

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

#2


0  

require_tree . already requires all the separate stylesheets in the same folder or subfolders.

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

If you want to include some specific stylesheet (say something.css.scss), you can do:

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

*= include something

However if you use variables in your SASS files which you want to use across different files, the comment style includes don't work. You'd need to import each file separately:

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

@import 'something';