Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
iconfont-webpack-plugin
Advanced tools
This plugin tries to keep the usage and maintenance of icon fonts as simple as possible.
a:before {
font-icon: url('./account.svg');
}
Browser Support: IE9+
Preprocessor Support: All - works with sass, less, stylus, postcss, vanilla css, ...
This plugin requires:
npm i --save-dev postcss-loader
npm i --save-dev iconfont-webpack-plugin
All you have to do is to add the plugin to your postcss loader plugins inside your webpack.config.js
:
const IconfontWebpackPlugin = require('iconfont-webpack-plugin');
module: {
rules: [
{
test: /\.css$/,
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: (loader) => [
// Add the plugin
new IconfontWebpackPlugin(loader)
]
}
}
]
}
]
},
Probably you won't need this but you can also pass some additional options.
Name | Type | Default | Description |
---|---|---|---|
resolve | {Function} | Required - A function which resolves the svg paths. See resolve | |
fontNamePrefix | {String} | '' | Allows to prefix the generated font name |
enforcedSvgHeight | {number} | 1000 | Scales all svg to the given height |
const IconfontWebpackPlugin = require('iconfont-webpack-plugin');
module: {
rules: [
{
test: /\.css$/,
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: (loader) => [
// Add the plugin
new IconfontWebpackPlugin({
resolve: loader.resolve,
fontNamePrefix: 'custom-',
enforcedSvgHeight: 3000,
})
]
}
}
]
}
]
},
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;
}
Shorthand for setting the icon size and the icon:
a:before {
font-icon: 80% url('./account.svg');
}
The main work of the iconfont-webpack-plugin is done by svg2ttf which converts svgs into fonts.
Therefore it inherits all its limitations.
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.
SVGs have some disadvantages and lack certain features especially when used inside pseudo elements:
Like all technologies there are disadvantages when using icon fonts.
We tried to apply best practices to solve the main issues for you.
This project is licensed under MIT.
FAQs
Simple icon font handling for webpack
The npm package iconfont-webpack-plugin receives a total of 1,990 weekly downloads. As such, iconfont-webpack-plugin popularity was classified as popular.
We found that iconfont-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.