Babel plugin that transforms SVG files into React components. Version 3.0.3 is the current stable release, with no active development since 2019. It works by running SVGO optimization followed by a Babel transform to produce a component that renders the SVG as JSX. Key differentiators: integrates with webpack via react-svg-loader, supports SVGO options, and outputs functional components. Alternatives like @svgr/webpack offer more features and are actively maintained.
npm install babel-plugin-react-svgVerified import paths — ran on the pinned version, not inferred.
Shows Babel plugin configuration and how to import an SVG as a React component.
Migrate to @svgr/webpack (see svgr.io).
Update Node.js to version >=8. For class component output, downgrade to v1.x.
Avoid reusing the same SVGO instance across multiple files; plugin handles this internally now.
Upgrade to Babel 7 or pin to babel-plugin-react-svg@^2.1.0.
Use react-svg-loader webpack loader instead of configuring manually.
Ensure your SVG files have the .svg extension and are imported with correct path.
Add react-svg-loader to webpack rules: { test: /\.svg$/, use: ['babel-loader', 'react-svg-loader'] }npm install @babel/plugin-syntax-jsx --save-dev
Use valid options: { svgo: boolean, expandProps: 'start'|'end'|false }