#typescript #react #svg #component

app rusty-svg

A CLI to convert SVG files into React components

4 releases

new 0.1.3 Apr 11, 2025
0.1.2 Apr 2, 2025
0.1.1 Apr 2, 2025
0.1.0 Apr 2, 2025

#172 in Command line utilities

Download history 398/week @ 2025-04-02

398 downloads per month

MIT license

1MB
184 lines

Contains (Mach-o exe, 3MB) bin/rusty-svg

rusty-svg

Convert SVG files into React components (TypeScript or JavaScript) with ease.
Supports interactive CLI and configuration via rusty-svg.config.toml.

✨ Features

  • ✅ 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)

🚀 Installation

npm i -D rusty-react-svg

🧪 Usage

CLI options

rusty-svg --input icons --output components --typescript

Interactive mode (no arguments)

rusty-svg

You will be prompted to choose:

  • Input folder
  • Output folder
  • Whether to use TypeScript
  • Overwrite confirmation if output folder exists

⚙️ Config File (rusty-svg.config.toml)

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.

💡 Example Output

If home.svg exists, the result will be:

TypeScript (tsx)

import React from 'react';

type Props = React.SVGProps<SVGSVGElement>;

const IconHome = (props: Props) => <svg {...props}>...</svg>;

export default IconHome;

JavaScript (jsx)

import React from 'react';

const IconHome = (props) => <svg {...props}>...</svg>;

export default IconHome;

📦 In a React Project

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.

🛠 Roadmap

  • index.ts generator
  • Option to optimize SVG (like SVGO)
  • Custom config file path (--config ./my-config.toml)
  • --no-config flag to ignore config file

Dependencies

~7–20MB
~208K SLoC