Rails资产pipleline:编译为多个样式表 [英] Rails asset pipleline: compile to multiple stylesheets
问题描述
由于特定的设置,我想将已编译的样式表分为两个文件.这是因为可以解析CSS的Java应用程序需要CSS(的一部分),但是它有点bug,无法处理某些css-(hack)-语法.因为我无法修改此Java应用程序,所以我只希望向它提供所需的CSS,并且可以确保它的正确性.
Due to a specific setup, I would like to split the compiled stylesheets in two files. This is because (a part of) the CSS is needed for a Java application which can parse the CSS, but it is a bit buggy and can't handle some css-(hack)-syntax. Because I am unable to modify this Java application, I want to feed it only the CSS which it needs and of which I can make sure it is correct.
因此,通常资产管道只会产生一个'/assets/application-[..].css'文件.它将允许它根据我所做的文件选择生成'/assets/custom-[..].css'.仍然可以预先编译.
So, normally the assets pipeline would produce just one '/assets/application-[..].css' file. It would to let it also generate '/assets/custom-[..].css', based on a file selection I make. This still can be pre-compiled.
有没有办法做到这一点?尽管我知道这不是理想的设置.
Is there a way to do this? Although I understand this is not the ideal setup..
推荐答案
要告诉rails您希望预编译的其他文件,可以将它们添加到config.assets.precompile
设置中.
To tell rails about additional files you wish to have precompiled, you can add them to the config.assets.precompile
setting.
config.assets.precompile += ["other_application.css"]
您只能在HTML中看到application.css
,因为这是您要包含的唯一文件
You only see application.css
in your HTML because that's the only file you're including
<%= stylesheet_link_tag "application" %>
如果apps/assets/stylesheets
目录中有一些custom.css.scss
,它将像application.css
一样进行编译.
If you have some custom.css.scss
in your apps/assets/stylesheets
directory, it will be compiled just like application.css
.
例如,我可能有
- _common.css.scss
- application.css.erb.scss
- other_application.css.erb.scss
app/assets/stylesheets
中的
.在非部分文件的顶部,我将放置
in app/assets/stylesheets
. In the top of the non-partial files I will put
@import "common";
包含_common.css.scss
.现在,我可以在布局中相互引用一个独立的样式表.
to include _common.css.scss
. I can now reference either stylesheet independent of one another in a layout.
<%= stylesheet_link_tag "application" %>
# or
<%= stylesheet_link_tag "other_application" %>
这篇关于Rails资产pipleline:编译为多个样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!