From e2e536ba6bc81736d00ca141d8a220fb80efd6b9 Mon Sep 17 00:00:00 2001 From: AHMED SALIH AC <36645339+adsalihac@users.noreply.github.com> Date: Fri, 23 Jun 2023 00:13:29 +0530 Subject: [PATCH 1/2] React native 0.72 and above metro.config.js --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 54ebb18..0ea708d 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,40 @@ module.exports = (async () => { })(); ``` +#### For React Native v0.72 or newer + +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`: + +```js +const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); +const defaultSourceExts = require('metro-config/src/defaults/defaults').sourceExts; +const defaultAssetExts = require('metro-config/src/defaults/defaults').assetExts; +/** + * Metro configuration + * https://facebook.github.io/metro/docs/configuration + * + * @type {import('metro-config').MetroConfig} + */ + +module.exports = mergeConfig(getDefaultConfig(__dirname), { + transformer: { + babelTransformerPath: require.resolve('react-native-svg-transformer'), + getTransformOptions: async () => ({ + transform: { + experimentalImportSupport: false, + inlineRequires: true, + }, + }), + }, + resolver: { + assetExts: defaultAssetExts.filter(ext => ext !== 'svg'), + sourceExts: [...defaultSourceExts, 'svg'], + }, +}); +``` + ### Using TypeScript 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): From e8d05c0265dbb53c14686e655920a1d22e98036a Mon Sep 17 00:00:00 2001 From: AHMED SALIH AC <36645339+adsalihac@users.noreply.github.com> Date: Fri, 30 Jun 2023 03:15:41 +0000 Subject: [PATCH 2/2] updated metro config in readme --- README.md | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0ea708d..2dcb035 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ module.exports = (async () => { })(); ``` -#### For React Native v0.72 or newer +#### For React Native v0.72.1 or newer Merge the contents from your project's `metro.config.js` file with this config (create the file if it does not exist already). @@ -104,30 +104,27 @@ Merge the contents from your project's `metro.config.js` file with this config ( ```js const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); -const defaultSourceExts = require('metro-config/src/defaults/defaults').sourceExts; -const defaultAssetExts = require('metro-config/src/defaults/defaults').assetExts; + +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(getDefaultConfig(__dirname), { - transformer: { - babelTransformerPath: require.resolve('react-native-svg-transformer'), - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - }, - resolver: { - assetExts: defaultAssetExts.filter(ext => ext !== 'svg'), - sourceExts: [...defaultSourceExts, 'svg'], - }, -}); +module.exports = mergeConfig(defaultConfig, config); ``` ### Using TypeScript