Grunt-contrib-sass不会创建config.rb文件?

时间:2014-12-17 19:05:13

标签: sass gruntjs compass-sass mixins grunt-contrib-sass

我正在使用Grunt-Contrib-Sass,我似乎无法在任何地方找到config.rb文件(如果它正在创建一个)。我需要它来分配http_fonts_path的路径,因为我正在使用Compass font-face mixin,它似乎返回字体路径“./fonts”

这是mixin代码:

@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”添加到网址。

@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文件中生成的网址。

1 个答案:

答案 0 :(得分:0)

所以基本上我将config.rb文件添加到项目的根目录中(运行grunt的地方)。

http_fonts_path = '../fonts/'
http_images_path = '../images/'

relative_assets = false

然后,我改变了font-face mixins的用法:

@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;无论用户是否指定了默认值或一个默认值。