为什么在默认 application.css 中 require_tree 在 require_self 之前?
Why is require_tree before require_self in default application.css?
我注意到在生成新的 Rails 4.2 应用程序后,application.css 中要求的顺序已更改。
*= require_tree .
*= require_self
这不应该反过来吗?即使在 Guides 也不是这样...
进行此更改是为了允许 application.css
中定义的样式覆盖以前包含的样式。
请参阅 Rails issue #11639 and this commit,它更改了 require
指令的顺序。
如官方文档所述here, and also explained in this SO answer here:
This puts the CSS contained within the file (if any) at the precise location of the require_self call.
这与我在评论中写的略有不同,因为如上述引用所示,清单中的 JS 或 CSS 将插入到 require_self
的位置。如果您以后的资产依赖于您在清单中编写的内容,这一点就变得很重要。
当然,如果您要这样做,最好还是将该 "inline" 资产放在一个单独的文件中,只是为了保持清单干净。
我注意到在生成新的 Rails 4.2 应用程序后,application.css 中要求的顺序已更改。
*= require_tree .
*= require_self
这不应该反过来吗?即使在 Guides 也不是这样...
进行此更改是为了允许 application.css
中定义的样式覆盖以前包含的样式。
请参阅 Rails issue #11639 and this commit,它更改了 require
指令的顺序。
如官方文档所述here, and also explained in this SO answer here:
This puts the CSS contained within the file (if any) at the precise location of the require_self call.
这与我在评论中写的略有不同,因为如上述引用所示,清单中的 JS 或 CSS 将插入到 require_self
的位置。如果您以后的资产依赖于您在清单中编写的内容,这一点就变得很重要。
当然,如果您要这样做,最好还是将该 "inline" 资产放在一个单独的文件中,只是为了保持清单干净。