A Webpack loader that transforms SVG files into reusable React components. Current stable version is 0.4.6. Allows inline SVG usage as React components or composition of multiple SVGs. Supports query parameters for component naming, attribute mapping, CSS class prefixing, and custom filter functions. Does not require Babel for output (ES5-7 compatible). Works with React >=0.14. Key differentiators: supports SVG/XML string or object tree input, filter API for node modification, and works as both a loader and pre-loader.
npm install svg-react-loaderVerified import paths — ran on the pinned version, not inferred.
Configures webpack to load SVG files as React components, with a filter to remove fill attributes.
Upgrade React to at least 0.14. For older React versions, use svg-react-loader@0.3.x.
Ensure your webpack config does not expect Babel output from this loader. Adjust transpilation pipeline if needed.
Always prefix SVG imports with 'svg-react-loader?' or configure in webpack module.rules.
Use module.rules with 'use' and 'loader' options instead of 'loaders' array.
Always invoke this.update(value) inside filter functions after modifying the SVG object tree.
Run npm install --save-dev svg-react-loader
Add a rule in webpack.config.js: { test: /\.svg$/, use: 'svg-react-loader' }Change import to include loader: import Icon from 'svg-react-loader!../svg/my-icon.svg';
Upgrade svg-react-loader to >=0.4.0: npm install svg-react-loader@latest