To load SVG files as icon data in a Webpack project, install @yzfe/svgicon-loader as a development dependency and add it to your module rules.
Key options:
svgFilePath: An array of paths to your SVG files.svgoConfig: Custom SVGO configuration (set to null to use defaults).component: Set to 'react' if you are using React to load SVGs as components.
// webpack.config.js
{
module: {
rules: [
{
test: /\.svg$/,
include: ['SVG file path'],
use: [
'babel-loader',
{
loader: '@yzfe/svgicon-loader',
options: {
svgFilePath: ['SVG file path'],
// Custom svgo configuration
svgoConfig: null,
// If you are using react, it is recommended to configure the component option for react and load the svg file as react components.
component: 'react',
}
}
]
},
]
}
}