Convert react-native-svg TS/TSX icon components into static .svg files.
unsvgr-demo.mp4
bun install unsvgr
- or
bunx unsvgrThe package exposes a bin:
unsvgrunsvgr [input] [outputDir] [options]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.
-
-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
- 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.
unsvgr example/components/icon.tsxunsvgr example/components/icon.tsx example/components/svgunsvgr example/components/icon.tsx --output example/components/svgunsvgr example/componentsunsvgrunsvgr --input example/componentsunsvgr example/components/icon.tsx example/components/svg --nanoThe 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.
git clone https://github.com/mzaien/unsvgr
cd unsvgr
bun installbun testcd example
bun install
bun run convert-svg- 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.