Docs

@svgt/cli

A CLI to transform SVG files into frontend components.

Installation

It requires Node.js v22.13 or later.

Run it without installing:

npx @svgt/cli arrow-left.svg --framework react

Or add it globally to your system:

npm i -g @svgt/cli

Usage

svgt <files or folders...> --framework <framework> [options]
cat icon.svg | svgt --framework <framework> [options]
  • Convert a single SVG file. This writes ArrowLeft.tsx to the current folder:
svgt arrow-left.svg --framework react
  • Write it to another folder:
svgt arrow-left.svg --framework react --out src/components
  • Convert every SVG file in a folder, including its subfolders. Hidden folders, node_modules, dist and build are skipped:
svgt icons/ --framework svelte --out src/lib/icons
  • Pick the files from a list. When you pass no files or folders and stdin is a terminal, the CLI lists every SVG under the current folder:
svgt --framework react
KeyAction
SpaceSelect or clear a file
aSelect all
iInvert the selection
EnterConvert the selection
EscCancel
  • Read the SVG from stdin. The component is named SvgIcon unless you pass --name:
cat icon.svg | svgt --framework vue --name ArrowLeft

Options

OptionDescription
-f, --framework <name>Required. react, svelte, vue, angular, astro or web-components.
-o, --out <folder>Folder to write the components to. Defaults to the current folder.
-n, --name <name>Component name, for a single SVG only. Defaults to the file name in PascalCase, or SvgIcon from stdin.
--jsOutput JavaScript instead of TypeScript. Fails with Vue and Angular, which have no TypeScript option.
--no-dimensionsRemove width and height from the root <svg>.
--svg-prop <name=value>Set an attribute on the root <svg>. Repeat it for more attributes. A bare name removes the attribute.
--expand-props <pos>Where to spread the props on the root <svg>: start, end or none. Defaults to end.
--export-type <type>default or directly (export const / export class). Defaults to default. Fails with any framework other than React and Web Components.
--forceOverwrite existing files without asking.
-h, --helpShow the help.
-v, --versionShow the version.

Each option maps to a transform() option, documented in the @svgt/core README:

svgt icon.svg -f react --svg-prop aria-hidden=true --svg-prop class --expand-props start

Output files

Files are named after each framework's convention:

FrameworkFile
ReactArrowLeft.tsx / .jsx
SvelteArrowLeft.svelte
VueArrowLeft.vue
Angulararrow-left.component.ts
AstroArrowLeft.astro
Web Componentsarrow-left.ts / .js
  • When a file already exists, the CLI asks before overwriting it: y for yes, n for no (the default when you press Enter), a to overwrite it and every file after it. Without a terminal to ask in, or when the SVG comes from stdin, existing files are skipped unless you pass --force.
  • If an SVG fails to parse, that SVG is skipped. If two SVGs would write the same file, such as arrow-left.svg and ArrowLeft.svg, the first is written and the second is skipped. In both cases the other SVGs are still written and the command exits with code 1.

License

MIT