字蛛webfont 安装及使用方法

先安装nodejs和git,比如放在D:/nodejs/  文件夹

cmd 进入该文件夹,安装npm install express

安装 npm install font-spider -g

安装 npm install grunt-font-spider --save-dev

安装 npm install gulp-font-spider --save-dev

至此,安装完成。比如我们要压缩 F:/test/www/  目录下的字体,先把ttf字体放在 www/font/ 文件夹里,

然后用cmd进入www文件夹,执行:font-spider index.html 或者font-spider *.html 即可。

然后在css文件里参照此引用 :

/*声明 WebFont*/
@font-face {
  font-family: 'pinghei';
  src: url('../font/pinghei.ttf');
  src:
    url('../font/pinghei.eot') 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';
}

  字体文件依然放在font文件夹里。这样就ok了。

官网:http://font-spider.org/

原文地址:https://www.cnblogs.com/happyty/p/4766583.html