安装
npm install font-spider -g
在html中使用字体
在 CSS 中声明字体
/*声明 WebFont*/
@font-face {
font-family: ‘pinghei’;
src: url(‘../font/pinghei.eot’);
src:
url(‘../font/pinghei.eot?#font-spider’) format(’embedded-opentype’),
url(‘../font/pinghei.woff’) format(‘woff’),
url(‘../font/pinghei.ttf’) format(‘truetype’),
url(‘../font/pinghei.svg’) format(‘svg’);
font-weight: normal;
font-style: normal;
}
/*使用选择器指定字体*/
.home h1, .demo > .test {
font-family: ‘pinghei’;
}
压缩 WebFont
命令font-spider [options] <htmlFile …>
注意:实际上是把字体文件拷贝一个副本并把没有使用到的字体清除掉,从而减少字体文件大小。
Options
-h, –help 输出帮助信息
-V, –version 输出当前版本号
–info 仅提取 WebFont 信息显示,不压缩与转码
–ignore <pattern> 忽略的文件配置(可以是字体、CSS、HTML)
–map <remotePath,localPath> 映射 CSS 内部 HTTP 路径到本地
–debug 开启调试模式
–no-backup 关闭字体备份功能
–silent 不显示非关键错误
–revert 恢复被压缩的 WebFont