Supported frameworks
Better SVG works seamlessly with these frameworks:- React (
.jsx,.tsx) - Full JSX support with camelCase attributes - Vue (
.vue) - Vue directives and template syntax preserved - Svelte (
.svelte) - Svelte directives and bindings preserved - Astro (
.astro) - Astro directives preserved - HTML (
.html) - Standard HTML/SVG - PHP, EJS, ERB, Liquid - Template languages
JSX transformation
How it works
When you optimize an inline SVG in React or TypeScript React files, Better SVG:Detects JSX syntax
Identifies JSX-specific patterns like
className, camelCase attributes, expression values {value}, and spread operators {...props}.Converts to valid SVG
Transforms JSX syntax into valid SVG XML that SVGO can process:
className→classstrokeWidth→stroke-width{value}→ encoded placeholder{...props}→data-spread-*attribute
JSX detection
The extension automatically detects if an SVG uses JSX syntax by checking for:Attribute mapping
Better SVG maintains a comprehensive mapping of JSX camelCase to SVG kebab-case attributes:Framework-specific examples
React / TypeScript React
Better SVG automatically handles React’s JSX syntax:classNameis preserved (not converted toclass)strokeWidthandfillRuleremain in camelCase- The path is optimized (unnecessary
Mcommand removed)
Vue
Vue directives are detected and preserved::width(shorthand forv-bind:width)@click(shorthand forv-on:click)v-bind:height
Svelte
Svelte directives are also preserved:on:clickbind:clientWidth- Expression values
{x}and{y}
Astro
Astro client directives are preserved:Optimization behavior
React/TypeScript React (camelCase mode)
Whendocument.languageId is javascriptreact or typescriptreact:
- Attributes are converted:
strokeWidth↔stroke-width className↔class- Expression values are encoded and decoded
Other frameworks (kebab-case mode)
For Vue, Svelte, Astro, and HTML:- Attributes remain in kebab-case
- Framework directives (
:,@,v-,on:,bind:,client:) are preserved - Expression syntax is encoded and decoded
Technical implementation
The transformation process uses these key functions:svgTransform.ts and handle all the complexity of converting between JSX and SVG while preserving framework-specific syntax.