#webpack-config-svg-icon
A config for Webpack for loading .svg
icon files as React components.
Install:
yarn add webpack-config-svg-icon
Add to your webpack.config.babel.js
:
import svgIcon from `webpack-config-svg-icon`;
svgIcon({/* options */})({
/* existing webpack configuration */
})
Name | Default | Description |
---|---|---|
iconPath |
asset/icon |
... |
test |
/\.icon\.svg$/ |
... |
replaceColor |
... | ... |
svgo |
... | ... |
How to configure SVGO...
SVGs become React components...
How to dynamically add icons...
const context = require.context(process.env.ICON_PATH, false, /\.icon\.svg$/);
...
svgIcon({replaceColor: /^#(000){1,2}$/})({
/* existing webpack configuration */
})
Set up an icon component with display inline-block...
<Icon type='type'/>