使用gulp-iconfont-css,我試圖將Material Design svg編譯成字體。這是我Gulpfile.js部分:自定義圖標字體未加載
gulp.task('iconfont', function(){
gulp.src(paths.svg)
.pipe(iconfontCss({
fontName: 'material-design', // required
path: './www/sass/templates/_icons.scss',
targetPath: '../sass/_icons.scss',
fontPath: '/fonts/'
})).pipe(iconfont({
fontName: 'material-design', // required
}))
.pipe(gulp.dest('./www/fonts/'));
});
現在我的模板:
@font-face {
font-family: "<%= fontName %>";
src: url('<%= fontPath %><%= fontName %>.eot');
src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'),
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
url('<%= fontPath %><%= fontName %>.ttf') format('truetype'),
url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg');
}
.icon:before {
font-family: "<%= fontName %>";
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-style: normal;
font-variant: normal;
font-weight: normal;
// speak: none; // only necessary if not using the private unicode range (firstGlyph option)
text-decoration: none;
text-transform: none;
}
<% _.each(glyphs, function(glyph) { %>
<% var array = glyph.fileName.split('_') %>
.icon-<%= array.slice(1, array.length - 1).join('-') %>:before {
content: "\<%= glyph.codePoint %>";
}
<% }); %>
問題:我的圖標不加載當我創建這樣一個元素:
<i class="icon-send"></i>
我什麼都看不到。並且字體永遠不會下載到服務器上(在網絡日誌中)。此外,圖標使用不同的值定義了兩次。提取:
@font-face {
font-family: "material-design";
src: url('/fonts/material-design.eot');
src: url('/fonts/material-design.eot?#iefix') format('eot'), url('/fonts/material-design.woff') format('woff'), url('/fonts/material-design.ttf') format('truetype'), url('/fonts/material-design.svg#material-design') format('svg'); }
.icon:before {
font-family: "material-design";
...
text-transform: none; }
.icon-3d-rotation:before {
content: "\E001"; }
.icon-3d-rotation:before {
content: "\E002"; }
.icon-accessibility:before {
content: "\E003"; }
.icon-accessibility:before {
content: "\E004"; }
你驗證路徑的字體是正確的?或者生成的CSS有效? – cimmanon 2014-10-18 18:43:53
這是生成的CSS文件https://gist.github.com/vinz243/7f793f97d359bc8e4152沒有任何404或任何字體的請求(除roboto外) – Vinz243 2014-10-18 19:44:18