Icon maker loader
Webpack loader to load svg directly to your code
Installation
npm install icon-maker-loader
- if you dont have a css and fonts (eot,svg,ttf,woff) loader, you can use
css-loader
and url-loader
.
Usage
webpack configuration
const path = require('path');
module.exports = {
...
module: {
loaders: [
{
test: /\.svg$/,
loader: 'icon-maker',
include: path.join(__dirname, 'icons')
}, {
test: /\.css$/,
loader: 'css'
}, {
test: /\.(woff|eot|ttf|svg)$/,
loader: 'url',
exclude: path.join(__dirname, 'icons')
}
]
}
};
js example (react)
import React, { Component } from 'react';
import yinYan from './icons/yin-yan.svg';
export default MyComponent extends Component {
render() {
return (
<div>
Look at my icon!
<span className={yinYan} />
</div>
);
}
}
html example (requires html-loader)
<div>
Look at my icon!
<span class="${require('./icons/yin-yan.svg')}">
</span>
</div>
parameters (query params to the loader)
fontFamily
- (default default
), can split your icons to multiple font families (for instance, better loading for different pages of your application).files
- (default eot,svg,ttf,woff
), can decide which font files will be generated.localCss
- (default false
) - will generate css with local scope to be used with css-loader (you can also convert all of your classes to local using css-loader?modules
and then this option is not needed).
Example of parameters
icon-maker?fontFamily=login&files=eot,svg&localCss