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

@maecia/iconfont-plugin-webpack

v1.1.4

Published

Iconfont Generator.

Downloads

1

Readme

npm deps

iconfont-plugin-webpack

Automatically generate Webfonts from your SVGs using Webpack

Installation

npm install iconfont-plugin-webpack

Usage

You can see a simple example within the Demo Config, but basically you just need to include the package at the top of your webpack config like this:

const IconfontPlugin = require('iconfont-plugin-webpack');

And then set up the configuration within the webpackModule.plugins like this:

new IconfontPlugin({
    src: './src/asset/iconfont', // required - directory where your .svg files are located
    family: 'iconfont', // optional - the `font-family` name. if multiple iconfonts are generated, the dir names will be used.
    dest: {
        font: './src/font/[family].[type]', // required - paths of generated font files
        css: './src/css/_iconfont_[family].scss' // required - paths of generated css files
    },
    watch: {
        pattern: 'src/asset/iconfont/**/*.svg', // required - watch these files to reload
        cwd: undefined // optional - current working dir for watching
    },
    cssTemplate: function() {}// optional - the function to generate css contents
})

Resulting SCSS

The result will be a directory with Fonts in the formats eot, svg, ttf and woff as well as a .scss file with helping mixins for your iconfont. By default this .scss looks something like this:

$__iconfont__data: map-merge(if(global_variable_exists('__iconfont__data'), $__iconfont__data, ()), (
	// iconfont data here
));


$create-font-face: true !default; // should the @font-face tag get created?

// should there be a custom class for each icon? will be .filename
$create-icon-classes: true !default; 

// what is the common class name that icons share? in this case icons need to have .icon.filename in their classes
// this requires you to have 2 classes on each icon html element, but reduced redeclaration of the font family
// for each icon
$icon-common-class: 'icon' !default;

// if you whish to prefix your filenames, here you can do so.
// if this string stays empty, your classes will use the filename, for example
// an icon called star.svg will result in a class called .star
// if you use the prefix to be 'icon-' it would result in .icon-star
$icon-prefix: '' !default; 

// helper function to get the correct font group
@function iconfont-group($group: null) {
  // ...
}

// helper function to get the correct icon of a group
@function iconfont-item($name) {
  // ...
}

// complete mixing to include the icon
// usage:
// .my_icon{ @include iconfont('star') }
@mixin iconfont($icon) {
  // ...
}

// creates the font face tag if the variable is set to true (default)
@if $create-font-face == true {
  @font-face {
   font-family: "iconfont";
   src: url('../fonts/iconfont.eot'); /* IE9 Compat Modes */
   src: url('../fonts/iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
      url('../fonts/iconfont.woff') format('woff'), /* Pretty Modern Browsers */
      url('../fonts/iconfont.ttf')  format('truetype'), /* Safari, Android, iOS */
      url('../fonts/iconfont.svg') format('svg'); /* Legacy iOS */
  }
}

// creates icon classes for each individual loaded svg (default)
@if $create-icon-classes == true {
  .#{$icon-common-class} {
    font-style: normal;
    font-weight: 400;

    @each $icon, $content in map-get($__iconfont__data, "iconfont") {
      &.#{$icon-prefix}#{$icon}:before {
        font-family: "iconfont";
        content: iconfont-item("iconfont/#{$icon}");
      }
    }
  }
}

Testing the demo build

In order to test the demo build included in this package all you need to do is clone this repository, head into the root folder and execute these commands:

npm install
npm run demo

You will then find the generated fonts within /demo/fonts and the generated .scss within /demo/scss.

If the fonts get bigger than 8192 bytes they will get extracted into their own files, otherwhise file-loader will embed them as base64 directly into the .css (See configuration for file-loader in demo/webpack.config.js)

Maintainers