CLI for React SVG Loader

3.0.3 · active · verified Wed Apr 22

react-svg-loader-cli is a command-line interface tool designed to convert SVG files into optimized React components. It is part of the broader `react-svg-loader` ecosystem, which also includes webpack and rollup plugins. The package leverages SVGO for SVG optimization, generating functional React components (arrow functions) that can accept standard React props. The current stable version is 3.0.3. Release cadence is irregular, driven by bug fixes, dependency upgrades, and Node.js version support. Key differentiators include its focused CLI approach for batch processing SVGs and its integration with SVGO, providing a streamlined workflow for developers who prefer a command-line utility over build tool integrations. It allows for direct transformation of SVG assets into reusable React components.

Common errors

Warnings

Install

Quickstart

Demonstrates global installation, basic SVG processing, specifying output path, JSX output, and custom SVGO configuration.

# Install react-svg-loader-cli globally for easy access
npm install -g react-svg-loader-cli

# Or use npx for a one-off execution without global installation
# npx react-svg-loader-cli -i path/to/your/icon.svg -o src/components/Icon.js

# Example: Create a dummy SVG file for demonstration
echo '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>' > check-circle.svg

# Process the SVG, outputting a React component with JSX syntax
# The --jsx flag ensures JSX output (default changed in v2.0.0-alpha.0)
# The --svgo-config allows passing SVGO options directly, here preventing viewBox removal
react-svg-loader -i check-circle.svg -o src/components/CheckCircleIcon.js --jsx --svgo-config='{"plugins":[{"name":"preset-default", "params":{"overrides":{"removeViewBox":false}}}]}'

# To use this component in a React application:
# import CheckCircleIcon from './components/CheckCircleIcon';
# function MyComponent() {
#   return <CheckCircleIcon width={32} height={32} color="blue" />;
# }

view raw JSON →