最好的办法是使用内置的 Rails Asset Pipeline 来处理包含你的样式文件。
在您的app/assets/stylesheets文件夹中,您应该有一个名为application.css. 该文件使用Sprockets自动包含放置在app/assets/stylesheets文件夹内的所有 css 文件。
在文件的顶部,您会看到:
/*
* 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 .
*/
该*= require_self部分包括在这个实际application.css文件中编写的任何 css 样式,而该*= require_tree .部分包括在app/assets/stylesheets.
如果您想更改包含顺序,或指定特定样式表,例如mixins.css.scss位于 中的文件app/assets/stylesheets,请执行以下操作:
/*
* 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 .
*= require_mixins
*/
sprockets 的魔力将为您包含您的文件。