【问题标题】:Grails Asset Pipeline : Recalculating of url references in css failsGrails Asset Pipeline:重新计算css中的url引用失败
【发布时间】:2015-06-01 19:41:30
【问题描述】:

让我介绍一下背景。我们的 grails-app/assets 文件夹如下所示

grails-app
-- assets
----stylesheets
------parent.css
------somefolder
---------child.css
----fonts
------HelveticaNeue-Light.otf

我创建了一个 FontAssetFile.groovy

package app.asset

import java.util.regex.Pattern

class FontAssetFile extends asset.pipeline.AbstractAssetFile {
    static final List<String> contentType = ['font/opentype']
    static List<String> extensions = ['otf']
    static String compiledExtension = 'otf'
    static processors = []
    Pattern directivePattern = null

    public String directiveForLine (String line) { line }
}

parents.css的内容是

/*
*= require somefolder/child
*= require_self
*/

child.css的内容是

@font-face {
    font-family: "Helvetica Neue Light";
    src: url('../HelveticaNeue-Light.otf');
}

当我在开发环境中运行应用程序时,代码可以引用字体文件,因为浏览器请求127.0.0.1:8080/app/assets/somefolder/child.css

但是当我在生产环境中运行应用程序时,代码无法引用字体文件,因为浏览器现在请求127.0.0.1:8080/app/assets/parent.css child.css 文件已编译为一个文件,该文件的内容不在 parent.css 中 这意味着浏览器认为字体文件在 assets 文件夹之外,因为 parent.css 内容是

@font-face {
    font-family: "Helvetica Neue Light";
    src: url('../HelveticaNeue-Light.otf');
}

来自文档http://bertramdev.github.io/asset-pipeline/guide/usage.html#linking 我可以看到“....如果我们使用相对路径,资产管道会理解该路径并可以根据可能需要 CSS 的任何根文件重新计算新的相对路径” 但是当代码在 child.css 文件中引用 url 时,情况似乎并非如此。

我需要能够在开发和生产环境中引用字体文件。 我考虑过在生产中禁用编译,但是服务器将为每个资产提供单独的文件。我认为这不是最佳选择。

【问题讨论】:

    标签: grails asset-pipeline


    【解决方案1】:

    请升级到最新系列的插件,这个重新计算的 url 是固定的(1.9.9)现在已经相当老了

    【讨论】:

    • 谢谢。解决了网址问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多