
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',
family: 'iconfont',
dest: {
font: './src/font/[family].[type]',
css: './src/css/_iconfont_[family].scss'
},
watch: {
pattern: 'src/asset/iconfont/**/*.svg',
cwd: undefined
},
cssTemplate: function() {}
})
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;
$create-icon-classes: true !default;
$icon-common-class: 'icon' !default;
$icon-prefix: '' !default;
@function iconfont-group($group: null) {
}
@function iconfont-item($name) {
}
@mixin iconfont($icon) {
}
@if $create-font-face == true {
@font-face {
font-family: "iconfont";
src: url('../fonts/iconfont.eot');
src: url('../fonts/iconfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/iconfont.woff') format('woff'),
url('../fonts/iconfont.ttf') format('truetype'),
url('../fonts/iconfont.svg') format('svg');
}
}
@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