Created
February 3, 2019 15:31
-
-
Save DimitryDushkin/2016a41971b598634a7d16a78c3bb492 to your computer and use it in GitHub Desktop.
"Modern" build for react-native application for iOS 12+ as target. Native async-await, classes and much more!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isLegacyBuild = typeof process.env.BUNDLE_FOR_IOS === 'undefined'; | |
const iosVersion = process.env.BUNDLE_FOR_IOS || 12; | |
const modernBuild = { | |
presets: [ | |
[ | |
'@babel/preset-env', | |
{ | |
targets: `iOS >= ${iosVersion}`, | |
}, | |
], | |
'@babel/preset-react', | |
'@babel/preset-typescript', | |
], | |
plugins: [ | |
// Flow first https://github.com/babel/babel/issues/8417#issuecomment-417858286 | |
'@babel/plugin-transform-flow-strip-types', | |
[ | |
'@babel/plugin-transform-runtime', | |
{ | |
helpers: true, | |
regenerator: false, | |
} | |
], | |
'@babel/plugin-proposal-class-properties', | |
'@babel/plugin-proposal-export-default-from', | |
'@babel/plugin-proposal-optional-chaining', | |
'@babel/plugin-proposal-object-rest-spread', | |
'@babel/plugin-proposal-nullish-coalescing-operator', | |
// 'transform-remove-strict-mode', // @TODO: add strict to whole bundle once | |
] | |
}; | |
const legacyBuild = { | |
presets: [ | |
'module:metro-react-native-babel-preset' | |
], | |
plugins: [ | |
'transform-remove-console', | |
'@babel/plugin-transform-runtime', | |
] | |
}; | |
const config = { | |
plugins: [ | |
['module-resolver', { | |
'root': ['./src'], | |
'extensions': ['.js', '.ts', '.tsx', '.ios.js', '.android.js'] | |
}], | |
], | |
env: { | |
production: isLegacyBuild | |
? legacyBuild | |
: { | |
...modernBuild, | |
plugins: [ | |
...modernBuild.plugins, | |
'transform-remove-console', | |
] | |
}, | |
development: modernBuild, | |
} | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment