Grails Asset Pipeline:重新计算 css 中的 url 引用失败
Grails Asset Pipeline : Recalculating of url references in css fails
让我介绍一下背景。我们的 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中
这意味着浏览器认为字体文件在资产文件夹之外,因为 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 时,情况似乎并非如此。
我需要能够在开发和生产环境中引用字体文件。
我考虑过在生产中禁用编译,但服务器将为每个资产提供单独的文件。我认为这不是最佳选择。
请升级到最新系列的插件,这个重新计算的url是固定的(1.9.9)现在已经很旧了
让我介绍一下背景。我们的 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中
这意味着浏览器认为字体文件在资产文件夹之外,因为 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 时,情况似乎并非如此。
我需要能够在开发和生产环境中引用字体文件。 我考虑过在生产中禁用编译,但服务器将为每个资产提供单独的文件。我认为这不是最佳选择。
请升级到最新系列的插件,这个重新计算的url是固定的(1.9.9)现在已经很旧了