npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iconfont-create-plugin

v0.1.3

Published

a webpack plugin for create icon font

Downloads

5

Readme

IconFontCreatePlugin

安装


npm install iconfont-create-plugin

基本调用方式

同一般的webpack plugin引入iconfont-create-plugin,在webpack config中实例化。


const IconFontCreatePlugin = require('iconfont-create-plugin');

module.exports = {

    plugins: [
        new IconFontCreatePlugin({
            name:"icon",
            output:'/output/font',
        }),
    ],
}

IconFontCreatePlugin会将'/output/font'中的svg文件读取生成"eot", "woff", "ttf", "svg"四个字体文件,一个css文件,一个 预览的html文件

IconFontCreatePlugin支持参数

entry

svg图标路径,传该值会从传入路径下读取svg生成字体文件

entry:"/src/.icons",

或者是多个文件路径数组

entry:["/src/.icons","/src/icons"],

name

字体图标库的名称,该参数影响生成图标class名的前缀

output

生成的图标文件的输出地址,可指定为对象将html,css及font字体文件输出到三个不同的文件目录下,考虑发布css,font和预览html在不同目录下

{
    font:"/output/font",
    css:"/output/css/font",
    html:"/output/font"
}

publishPath

指定css中字体图标的引用路径,可以用于配置cdn路径或者是静态资源路径

new IconFontCreatePlugin({
    name:"icon",
    output:'/output/font',
    publishPath:"/publish/font/"
})

生成css

@font-face {
    font-family: "icon";
    src: url("/publish/font/icon.eot?#iefix") format("embedded-opentype"),
    url("/publish/font/icon.woff") format("woff"),
    url("/publish/font/icon.ttf") format("truetype"),
    url("/publish/font/icon.svg#iconFont") format("svg");
    font-weight: normal;
    font-style: normal;
}

suffix

考虑使用如sass这种的样式预处理,可以指定生成的文件的后缀名,如指定css为.sass后缀最终会生成icon.sass的字体样式文件

    new IconFontCreatePlugin({
        name:"icon",
        output:'/output/font',
        suffix:{
            css:".sass"
        },
        publishPath:"/publish/font/"
    })

styleTemplate与htmlTemplate

指定IconFontCreatePlugin生成的style文件模板及预览html文件的模板,满足预览模板更改的需求。模板使用ejs模板生成 提供了以下变量注入

    {
        name://字体库名,
        publishPath://发布路径,
        fontContent:""//生成字体css,
        fontName:{
            a:'\f1023s'
        }//生成字体列表
    }

按需加载图标

结合vusion-iconmaker这个loader可以实现字体图标的按需加载 如下配置loader

 rules: [
     { test: /\.svg$/, loader: 'vusion-iconmaker', include: path.join(__dirname, 'src/icons') },
 ]

业务代码中

     const test = 123;

     // const icons = require('icons-loader');

     const $app = document.getElementById('app');

     $app.innerHTML = `<i class="${require('./icons/test/arrow-left.svg')}"></i>
     <i class="${require('./icons/arrow-right.svg')}"></i>
     <i class="${require('./icons/arrow-up.svg')}"></i>

在业务代码中请求svg文件,loader将返回class名并通过Plugin将svg icon放到字体图标中