Let Metro handle import/export instead of Babel (#1772)

* Let Metro handle import/export instead of Babel

* Keep using Babel for ESM->CJS in tests
zio/stable
dan 2023-10-30 21:54:23 +00:00 committed by GitHub
parent 6c11c0b81d
commit 84ee64025f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -1,11 +1,17 @@
module.exports = function (api) {
api.cache(true)
const isTestEnv = process.env.NODE_ENV === 'test'
return {
presets: [
[
'babel-preset-expo',
{
lazyImports: true,
native: {
// Disable ESM -> CJS compilation because Metro takes care of it.
// However, we need it in Jest tests since those run without Metro.
disableImportExportTransform: !isTestEnv,
},
},
],
],

View File

@ -8,7 +8,17 @@ cfg.resolver.sourceExts = process.env.RN_SRC_EXT
cfg.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: true,
inlineRequires: true,
nonInlinedRequires: [
// We can remove this option and rely on the default after
// https://github.com/facebook/metro/pull/1126 is released.
'React',
'react',
'react/jsx-dev-runtime',
'react/jsx-runtime',
'react-native',
],
},
})