Skip to content

Commit f502aae

Browse files
authored
Add support for RN 73 with backwards compatibility (#45)
* add support for RN 73 with backwards compatibility * fix typo --------- Co-authored-by: Lukas Müller <18392496+WookieFPV@users.noreply.github.com>
1 parent f4c0c37 commit f502aae

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/cli/getAssets.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ const Server = require('metro/src/Server');
22
const { loadConfig } = require('metro-config');
33
const output = require('metro/src/shared/output/bundle');
44

5+
const getBabelTransformerPath = () => {
6+
try {
7+
// for RN 73+
8+
return require.resolve('@react-native/metro-babel-transformer');
9+
} catch (e) {
10+
// to ensure backwards compatibility with old RN versions (RN < 73)
11+
return require.resolve('metro-react-native-babel-transformer');
12+
}
13+
}
14+
515
async function getAssets(options) {
616
const args = {
717
entryFile: options.entryFile,
@@ -22,9 +32,7 @@ async function getAssets(options) {
2232
},
2333
transformer: {
2434
allowOptionalDependencies: true,
25-
babelTransformerPath: require.resolve(
26-
'metro-react-native-babel-transformer'
27-
),
35+
babelTransformerPath: getBabelTransformerPath(),
2836
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
2937
},
3038
}

0 commit comments

Comments
 (0)