rails资产管道重复css链接标记

时间:2015-03-12 17:50:48

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

我的application.css文件如下所示:

*= require_tree ./external
*= require_tree ./production
*= require_self
*= require custom

我有几个问题:

  1. 为什么我需要require_self? application.css不会自动生成包含其中所有内容的css文件,那么为什么我要说要包含它自己呢?

  2. 该文件为其调用的每个文件生成css链接标记,然后重复application.css文件中的每个文件:

    <link rel="stylesheet" media="all" href="/assets/external/font-awesome-2137eff45e0b64a17b4133bd2ddbdd78.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/external/font-classic1-75487e58c5e0c1ab46da239ad0414945.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/external/font-classic2-9acd884646fab77078ff59ccede6af64.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/external/font-classic3-640d45ed2364d0dff5a81ef9ce2c22fa.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/animate-5a353aa5390410216c837f4dbdf1e161.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/bootstrap-d2f563dbd757e49a399f0a7ed5febeae.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/contacters-64e62ddc273c2f5847f30d698ca14b67.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/jcagency-25ee42f4b0d3c4fe0df1eceb8f9fb6f8.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/owl.carousel-a12c5f6eb71a13cfc44317722283736c.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/owl.theme-691a2eb3c8d303b6416d9876419fec29.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/owl.transitions-1b9d47a45c85e9fa3f2f990b6d59519a.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/quotes-64e62ddc273c2f5847f30d698ca14b67.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/static_pages-64e62ddc273c2f5847f30d698ca14b67.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/style-3fe936e1b22ddf4d10e11085bac9a58c.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/production/styles-switcher-c79d19bcbdf90ee639dcfb1363d8f64c.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/application-951210d1179df1d65814be3ec67080c4.css?body=1" data-turbolinks-track="true" />
    <link rel="stylesheet" media="all" href="/assets/custom-235702796c9fbc52681919853d66009b.css?body=1" data-turbolinks-track="true" />
    

    这不是很糟糕吗?如何让它不重复?

1 个答案:

答案 0 :(得分:4)

  1. 您不必使用*= require_self。它的作用是将 application.css 中的所有css置于由require s的顺序确定的位置。
    事实上,摆脱它可能会很好,因为你应该避免将你的CSS放在 application.css 中。 如果你没有把*= require_self放在任何地方,那么来自self的css仍然会被加载,但那么它将是最后包含的样式表。

  2. 在开发模式下, application.css 不会编译为一个大文件(在开发模式下,资产按照清单文件中指定的顺序作为单独的文件提供:{ {3}})。所以你有多个文件是正常的。您可能没有在 application.css 中重复每个文件,是吗?