Convert SVG files into React components (TypeScript or JavaScript) with ease.
Supports interactive CLI and configuration via rusty-svg.config.toml
.
- ✅ Convert
.svg
files to.tsx
or.jsx
React components - ✅ Automatically applies props:
<svg {...props}>
- ✅ Interactive CLI prompts or command-line options
- ✅ Custom component prefix (e.g.
IconHome
) - ✅ Optional config file (
rusty-svg.config.toml
)
npm i -D rusty-react-svg
rusty-svg --input icons --output components --typescript
rusty-svg
You will be prompted to choose:
- Input folder
- Output folder
- Whether to use TypeScript
- Overwrite confirmation if output folder exists
If present, rusty-svg will use this file automatically.
input = "icons"
output = "components"
typescript = true
prefix = "Icon"
Config file overrides prompts unless explicitly overridden via CLI flags.
If home.svg exists, the result will be:
import React from 'react';
type Props = React.SVGProps<SVGSVGElement>;
const IconHome = (props: Props) => <svg {...props}>...</svg>;
export default IconHome;
import React from 'react';
const IconHome = (props) => <svg {...props}>...</svg>;
export default IconHome;
Add a script in your package.json:
"scripts": {
"generate:icons": "rusty-svg"
}
Then run:
npm run generate:icons
Ensure ~/.cargo/bin
is in your PATH if you installed rusty-svg with cargo install.
- index.ts generator
- Option to optimize SVG (like SVGO)
- Custom config file path (--config ./my-config.toml)
- --no-config flag to ignore config file