https://github.com/kristerkari/react-native-svg-transformer
yarn add react-native-svg
yarn add -D react-native-svg-transformer
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
const {assetExts, sourceExts} = defaultConfig.resolver;
/**
* Metro configuration
* <https://facebook.github.io/metro/docs/configuration>
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
},
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
},
};
module.exports = mergeConfig(defaultConfig, config);
// 위치 : ~/src/@types/declarations.d.ts
declare module '*.svg' {
import React from 'react';
import {SvgProps} from 'react-native-svg';
const content: React.FC<SvgProps>;
export default content;
}
// location : ~/.tsconfig.json
{
"extends": "@tsconfig/react-native/tsconfig.json",
"compilerOptions": {
...
"typeRoots": ["./node_modules/@types", "./src/@types"]
// ㄴ node_modules/@types는 필수적으로 명시해주고
// 그 다음에 svg 타입 선언을 위한 declar 파일위치를 명시해준다.
...
}
}