I successfully implemented this solution using the webfonts-generator plugin
Step 1:
- Add the dependency "webfonts-generator": "^0.3.5" in your package.json file
- Create a folder named icon inside src and place all your SVG files there
- Add the following code to your webpack.common.js file
webpack.common.js
const webfontsGenerator = require('webfonts-generator');
webfontsGenerator({
files: [
'src/icon/search.svg',
'src/icon/error.svg',
'src/icon/warning.svg'
],
dest: 'custom-fonts/',
fontName: 'custom-icons',
html: true,
templateOptions: {
baseClass: 'custom',
classPrefix: 'custom-'
}
}, function(error) {
if (error) {
console.log('Fail!', error);
} else {
console.log('Done!');
}
});
module.exports = {
loaders: [
{
test : /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader : 'file-loader'
}
]
}
- After building, the webfonts-generator plugin will create a folder called "custom-fonts" and generate CSS, EOT, TTF, HTML pages, etc.
- You can use the custom fonts by importing the generated CSS file
Something.html
<i class="custom custom-search"></i>
Output
https://i.sstatic.net/BYDBx.png
Reference:
Generator of webfonts from SVG icons
Automated webfont generation from SVG icons.