unsvgr
v0.0.4
Published
Convert react-native-svg TSX to static .svg (string transforms).
Maintainers
Readme
unsvgr
Convert react-native-svg TS/TSX icon components into static .svg files.
Demo
Install
bun install unsvgr
- or
bunx unsvgrCLI
The package exposes a bin:
unsvgrUsage
unsvgr [input] [outputDir] [options]Arguments
input(optional):.ts/.tsxfile or directory.- If omitted, the CLI scans
--input.
- If omitted, the CLI scans
outputDir(optional): output folder for generated SVG files.- If omitted, defaults to the same folder as each input file.
Options
-i, --input <dir>
Directory to scan wheninputargument is omitted.
Default:src/components/svgs-o, --output <dir>
Output directory (same meaning as positionaloutputDir).--nano
Skip icons that contain filter/mask features:<filter>or<mask>tagsfilter="..."ormask="..."attributes
Output behavior
- Converts all exported components that contain
<Svg>...</Svg>. - File name format:
<ComponentName>.svg - When scanning multiple files, all generated files are written to the selected output directory.
- Logs each generated file and component name.
- Skips non-convertible icons at the end with the component name and reason.
Examples
1) Convert one file to same folder
unsvgr example/components/icon.tsx2) Convert one file to explicit folder
unsvgr example/components/icon.tsx example/components/svg3) Convert one file using --output
unsvgr example/components/icon.tsx --output example/components/svg4) Scan a directory recursively for files containing <Svg>
unsvgr example/components5) Omit input and use default scan folder
unsvgr6) Omit input and provide custom scan folder
unsvgr --input example/components7) Use nano-safe mode
unsvgr example/components/icon.tsx example/components/svg --nanoExpression fallback resolution
The converter aggressively resolves static JSX fallback expressions before writing SVG attributes, including:
- local constants (
defaultColor) - imported object paths (
Colors.dark.icon) ||,??, ternary fallback branches- static template/string/number expressions
If an expression cannot be resolved deterministically, that icon is skipped as non-convertible and reported after conversion.
Contributing
git clone <repo-url>
cd rnsvg-to-svg
bun installRun tests
bun testDevelop against example app
cd example
bun install
bun run convert-svgCommon contribution workflow
- Add or update fixture icons in
example/components. - Run
bun run convert-svginexample. - Add/update tests in
index.test.ts. - Run
bun testat repo root.
