Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

astros-svgfont

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astros-svgfont

Astro的插件。根据svg生成字体文件和引用

latest
Source
npmnpm
Version
1.0.7
Version published
Weekly downloads
7
16.67%
Maintainers
1
Weekly downloads
 
Created
Source

svg自动合成字体中间件

本项目为Astros中间件

astros-svgfont会把img/svg目录下的svg图标生成eot,svg,ttf,woff四种字体,并自动生成对应svg名的css代码,插入到对应页面样式之前。

SVG文件存放位置

--assets
  --svg
      --icons(生成的字体名称就是目录名称,即icons)
        --car.svg
        --user.svg
      --button
        --loading.svg

根据以上目录结构,生成的字体分别icons和button

该中间件会根据svg名称自动生成对应的class,以icons为例:

@font-face(自动生成的)

@font-face {
    font-family: "icons";
    src: url("/fonts/font2.eot?v=true");
    src: url("/fonts/font2.eot?v=true") format("embedded-opentype"), url("/fonts/font2.woff?v=true") format("woff"), url("/fonts/font2.ttf?v=true") format("truetype"), url("/fonts/font2.svg?v=true") format("svg");
    font-weight: normal;
    font-style: normal;
}
CSS(自动生成)
.i-loading:before {
     content: "\e900";
    
 }
 .i-car:before {
    content: "\e605";
 }

使用方式

CSS

/* ICON基础类 */
.m-icon{
    display: inline-block;
    width: 50px;
    height: 50px;
    font-size: 24px;
    color: #dedede;
    font-family: "icons";
}

注意,这里需要你自己实现icon基类,引用对应的字体

HTML

<i class="m-icon i-loading"></i>

配置

如果需要指定字体生成目录,可以通过 fontPath参数配置

{
    name:'astros-svgfont',
    config:{
        fontPath:'/fonts/',  //字体文件存放路径,相对于 root/asset 路径
        base64:true          //移动端兼容性最好,pc不建议使用
    }
}

FAQs

Package last updated on 12 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts