我正在使用Grunt-Contrib-Sass,我似乎在任何地方都找不到config.rb文件(如果它正在创建一个(。我需要它为http_fonts_path分配路径,因为我使用的是指南针字体-face混合,它似乎返回了字体路径"./fonts">
这是混合代码:
@import "compass/css3";
@include font-face("Tw Cen MT", font-files("..fonts/tw_cen_mt/Tw_Cen_MT-webfont.woff", "..fonts/tw_cen_mt/Tw_Cen_MT-webfont.ttf", "..fonts/tw_cen_mt/Tw_Cen_MT-webfont.svg"), "..fonts/tw_cen_mt/Tw_Cen_MT-webfont.eot");
@include font-face("New Cicle Gordita", font-files("..fonts/new_cicle_gordita/New_Cicle_Gordita-webfont.woff", "..fonts/new_cicle_gordita/New_Cicle_Gordita-webfont.ttf", "..fonts/new_cicle_gordita/New_Cicle_Gordita-webfont.svg"), "..fonts/new_cicle_gordita/New_Cicle_Gordita-webfont.eot");
现在这是我得到的警告:
WARNING: 'Tw_Cen_MT-webfont.woff' was not found (or cannot be read) in ./fonts/..fonts/tw_cen_mt
WARNING: 'Tw_Cen_MT-webfont.ttf' was not found (or cannot be read) in ./fonts/..fonts/tw_cen_mt
WARNING: 'Tw_Cen_MT-webfont.svg' was not found (or cannot be read) in ./fonts/..fonts/tw_cen_mt
WARNING: 'Tw_Cen_MT-webfont.eot' was not found (or cannot be read) in ./fonts/..fonts/tw_cen_mt
WARNING: 'Tw_Cen_MT-webfont.eot?' was not found (or cannot be read) in ./fonts/..fonts/tw_cen_mt
WARNING: 'New_Cicle_Gordita-webfont.woff' was not found (or cannot be read) in ./fonts/..fonts/new_cicle_gordita
WARNING: 'New_Cicle_Gordita-webfont.ttf' was not found (or cannot be read) in ./fonts/..fonts/new_cicle_gordita
WARNING: 'New_Cicle_Gordita-webfont.svg' was not found (or cannot be read) in ./fonts/..fonts/new_cicle_gordita
WARNING: 'New_Cicle_Gordita-webfont.eot' was not found (or cannot be read) in ./fonts/..fonts/new_cicle_gordita
WARNING: 'New_Cicle_Gordita-webfont.eot?' was not found (or cannot be read) in ./fonts/..fonts/new_cicle_gordita
不用说,在CSS文件中的输出与警告相同,而不是我最初放入Sass文件mixin的内容。
但是,当我使用没有".."的路径时,它可以正常工作,并且不会将"./fonts"添加到 url 中。
@include font-face("Tw Cen MT", font-files("/tw_cen_mt/Tw_Cen_MT-webfont.woff", "/tw_cen_mt/Tw_Cen_MT-webfont.ttf", "/tw_cen_mt/Tw_Cen_MT-webfont.svg"), "/tw_cen_mt/Tw_Cen_MT-webfont.eot");
@include font-face("New Cicle Gordita", font-files("/new_cicle_gordita/New_Cicle_Gordita-webfont.woff", "/new_cicle_gordita/New_Cicle_Gordita-webfont.ttf", "/new_cicle_gordita/New_Cicle_Gordita-webfont.svg"), "/new_cicle_gordita/New_Cicle_Gordita-webfont.eot");
但是,这不是我想在我的 CSS 文件中生成的 URL。
所以基本上我在项目的根目录中添加了一个config.rb文件(从那里运行grunt(。
http_fonts_path = '../fonts/'
http_images_path = '../images/'
relative_assets = false
然后,我更改了字体-面部混合的用法,如下所示:
@import "compass/css3";
@include font-face("Tw Cen MT", font-files("tw_cen_mt/Tw_Cen_MT-webfont.woff", "tw_cen_mt/Tw_Cen_MT-webfont.ttf", "tw_cen_mt/Tw_Cen_MT-webfont.svg"), "tw_cen_mt/Tw_Cen_MT-webfont.eot");
@include font-face("New Cicle Gordita", font-files("new_cicle_gordita/New_Cicle_Gordita-webfont.woff", "new_cicle_gordita/New_Cicle_Gordita-webfont.ttf", "new_cicle_gordita/New_Cicle_Gordita-webfont.svg"), "new_cicle_gordita/New_Cicle_Gordita-webfont.eot");
我意识到,如果路径以正斜杠"/"开头,那么它将直接用作路径;但是,如果我使用其他任何东西,它会在它前面添加http_fonts_path;无论是否有默认的还是用户分配的。