Gathering detailed insights and metrics for react-native-svg-transformer
Gathering detailed insights and metrics for react-native-svg-transformer
Gathering detailed insights and metrics for react-native-svg-transformer
Gathering detailed insights and metrics for react-native-svg-transformer
@hitbit/expo-svg-transformer
Use svgr to reactify .svg files
@ornikar/react-native-svg-transformer
SVG transformer for react-native - fork of kristerkari
expo-svg-transformer
SVG transformer for react-native - fork of kristerkari
@tvthanh02/react-native-svg-transformer
SVG transformer for react-native
Import SVG files in your React Native project the same way that you would in a Web application.
npm install react-native-svg-transformer
Typescript
Module System
57.8
Supply Chain
47.5
Quality
71.9
Maintenance
50
Vulnerability
93.6
License
JavaScript (100%)
Total Downloads
63,736,219
Last Day
17,647
Last Week
459,333
Last Month
2,129,282
Last Year
21,908,114
MIT License
1,675 Stars
306 Commits
120 Forks
7 Watchers
6 Branches
22 Contributors
Updated on Jun 30, 2025
Minified
Minified + Gzipped
Latest Version
1.5.1
Package Id
react-native-svg-transformer@1.5.1
Unpacked Size
15.05 kB
Size
5.48 kB
File Count
10
Published on
May 02, 2025
Cumulative downloads
Total Downloads
Last Day
-13.3%
17,647
Compared to previous day
Last Week
-12.7%
459,333
Compared to previous week
Last Month
5.3%
2,129,282
Compared to previous month
Last Year
38%
21,908,114
Compared to previous year
React Native SVG transformer allows you to import SVG files in your React Native project the same way that you would in a Web application when using a library like SVGR to transform your imported SVG images into React components.
This makes it possible to use the same code for React Native and Web.
Import your .svg
file inside a React component:
1import Logo from "./logo.svg";
You can then use your image as a component:
1<Logo width={120} height={40} />
Make sure that you have installed the react-native-svg
library:
1npm install --save-dev react-native-svg-transformer
or
1yarn add --dev react-native-svg-transformer
Merge the contents from your project's metro.config.js
file with this config (create the file if it does not exist already).
metro.config.js
:
1const { getDefaultConfig } = require("expo/metro-config"); 2 3module.exports = (() => { 4 const config = getDefaultConfig(__dirname); 5 6 const { transformer, resolver } = config; 7 8 config.transformer = { 9 ...transformer, 10 babelTransformerPath: require.resolve("react-native-svg-transformer/expo") 11 }; 12 config.resolver = { 13 ...resolver, 14 assetExts: resolver.assetExts.filter((ext) => ext !== "svg"), 15 sourceExts: [...resolver.sourceExts, "svg"] 16 }; 17 18 return config; 19})();
Merge the contents from your project's metro.config.js
file with this config (create the file if it does not exist already).
metro.config.js
:
1const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config"); 2 3const defaultConfig = getDefaultConfig(__dirname); 4const { assetExts, sourceExts } = defaultConfig.resolver; 5 6/** 7 * Metro configuration 8 * https://reactnative.dev/docs/metro 9 * 10 * @type {import('metro-config').MetroConfig} 11 */ 12const config = { 13 transformer: { 14 babelTransformerPath: require.resolve( 15 "react-native-svg-transformer/react-native" 16 ) 17 }, 18 resolver: { 19 assetExts: assetExts.filter((ext) => ext !== "svg"), 20 sourceExts: [...sourceExts, "svg"] 21 } 22}; 23 24module.exports = mergeConfig(defaultConfig, config);
Merge the contents from your project's metro.config.js
file with this config (create the file if it does not exist already).
metro.config.js
:
1const { getDefaultConfig } = require("metro-config"); 2 3module.exports = (async () => { 4 const { 5 resolver: { sourceExts, assetExts } 6 } = await getDefaultConfig(); 7 return { 8 transformer: { 9 babelTransformerPath: require.resolve( 10 "react-native-svg-transformer/react-native" 11 ) 12 }, 13 resolver: { 14 assetExts: assetExts.filter((ext) => ext !== "svg"), 15 sourceExts: [...sourceExts, "svg"] 16 } 17 }; 18})();
Some React Native projects are using Expo modules without using expo-cli.
In such projects Expo's transformer is selected by default, and can be overwritten to correctly use React Native's transformer by adding react-native
to the require path:
1-require.resolve("react-native-svg-transformer") 2+require.resolve("react-native-svg-transformer/react-native")
You can also force Expo's transformer to always be used:
1-require.resolve("react-native-svg-transformer") 2+require.resolve("react-native-svg-transformer/expo")
If you are using TypeScript, you need to add this to your declarations.d.ts
file (create one if you don't have one already):
1declare module "*.svg" { 2 import React from "react"; 3 import { SvgProps } from "react-native-svg"; 4 const content: React.FC<SvgProps>; 5 export default content; 6}
SVGR has a configuration file, which makes it possible for you to customize how SVG images get transformed to React/React Native.
Read more about the configuration options: Configuring SVGR and SVGR options.
For example, if you want to change SVG image's fill color from red
to currentColor
(keep in mind that this will be used for all SVG images in your app).
.svgrrc
(create the file in your project's root folder if it does not exist)
1{ 2 "replaceAttrValues": { 3 "red": "currentColor" 4 } 5}
Edit your .svgrrc
file and include a line for replaceAttrValues
that matching a hex code to {props.fill}
1{ 2 "replaceAttrValues": { 3 "#000": "{props.fill}" 4 } 5}
And then make sure your path tag inside the SVG file fill
attribute is the hex code (in this case #000
).
1<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <path d="M2.965 6.0925C4.045 8.215 ..." fill="#000"/> 3</svg>
You can then use your image as a component:
1<Logo width={120} height={40} fill={"any color"} />
To use Jest
to test your React Native components that import .svg
images, you need to add this configuration that mocks the SVG images that are transformed to React components:
__mocks__/svgMock.js
:
1module.exports = "SvgMock";
Then, depending on where you have your Jest configuration:
package.json
:
1{ 2 "jest": { 3 "moduleNameMapper": { 4 "\\.svg": "<rootDir>/__mocks__/svgMock.js" 5 } 6 } 7}
or
jest.config.js
:
1module.exports = { 2 moduleNameMapper: { 3 "\\.svg": "<rootDir>/__mocks__/svgMock.js" 4 } 5};
At the moment react-native-svg does not support custom font families in iOS right out of the box. A workaround is to take your .svg
with custom fonts and convert it to outlines. This will replace text
tags for path
tags in your .svg
file.
In addition to React Native, this transformer depends on the following libraries:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
6 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 1/4 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More