GithubHelp home page GithubHelp logo

alexxnica / iconfont-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jantimon/iconfont-webpack-plugin

0.0 1.0 0.0 97 KB

Simple icon font handling for webpack

License: MIT License

JavaScript 99.25% CSS 0.75%

iconfont-webpack-plugin's Introduction

Icon Font Webpack Plugin

npm version Dependency Status Build status Build status

This plugin tries to keep the usage and maintenance of icon fonts as simple as possible.

Browser Support: IE9 - IE11 and all modern browsers

Installation

npm i --save-dev iconfont-webpack-plugin

Configuration

var IconfontWebpackPlugin = require('iconfont-webpack-plugin');

  // make sure you use the postcss loader:
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!postcss-loader'
      }
    ]
  },
  // add the plugin
  plugins: [
    new IconfontWebpackPlugin()
  ]

Advanced Configuration

var IconfontWebpackPlugin = require('iconfont-webpack-plugin');

  // make sure you use the postcss loader:
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'css-loader!postcss-loader'
      }
    ]
  },
  // add the plugin
  plugins: [
    new IconfontWebpackPlugin({
      fontNamePrefix: 'custom-'
    })
  ]

Usage

After setting up the plugin your css has now a new feature:
font-icon declarations

a:before {
  font-icon: url('./account.svg');
  transition: 0.5s color;
}

a:hover:before {
  color: red;
}

and it will be compiled into:

@font-face {
  font-family: i96002e;
  src: url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAA.....IdAA==") format('woff');
}

a:before {
  font-family: i96002e;
  content: '\E000';
  transition: 0.5s color;
}

a:hover:before {
  color: red;
}

Icon sizes

Shorthand for setting the icon size and the icon:

a:before {
  font-icon: 80% url('./account.svg');
}

Should you use icon fonts for everything?

No.

Icon fonts are really good for decorative icons (where the icon is purely ornamental and doesn’t incorporate core meaning or functionality).

For critical icons without fallbacks (like a hamburger menu icon) you should rather use SVGs. But also JPEGs, PNGs and even GIFs have their use cases.

Pick the best solution for your problem - there is no silver bullet. With this plugin it is pretty easy to use pixel images, svgs and font-icons side by side.

When should you use icon fonts over pure SVGs?

SVGs have some disadvantages and lack certain features especially when used inside pseudo elements:

What about all the rant on icon fonts?

Like all technologies there are disadvantages when using icon fonts.
We tried to apply best practices to solve the main issues for you.

License

This project is licensed under MIT.

iconfont-webpack-plugin's People

Contributors

jantimon avatar mimse avatar phaldan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.