This release is rather for feedback purpose than for production usage.
This plugin tries to keep the usage and maintainance of icon fonts as simple as possible.
npm i --save-dev iconfont-webpack-plugin
var path = require('path');
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()
]
If you set this plugin up properly you can finely use a font-icon
declarations
in your css/scss/sass/less/...
:
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;
}
SVGs have some disadvantages and lack certain features especially when using inside pseudo elements.
- CSS-Transform issues in older Internet Explorer versions
- IE9 - IE 10 scaling issues
- Fill color doesn't work on background SVG images
- Inline SVGs are resolved relative to the page not to the css
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 or even GIFs have their use cases.
Pick the best solution for your problem - there is no silver bullet.
This project is licensed under MIT.