mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 17:45:59 +00:00
e6cb02d61a
Summary: Rather than specifying Babel plugins in the `.babelrc` packaged with react-native, leverage a Babel preset to define the plugins (https://github.com/exponentjs/babel-preset-react-native). This allows for a much better user experience for those who want (or need) to override options in their project's `.babelrc`. Prior to this PR, if a user wanted to use a custom babel-plugin (or a custom set of babel plugins), they'd have either 1) manually override the `.babelrc` in the react-packager directory (or fork RN), or 2) specify a custom transformer to use when running the packager that loaded their own `.babelrc`. Note - the custom transformer was necessary because without it, RN's `.babelrc` options would supersede the options defined in the project's `.babelrc`...potentially causing issues with plugin ordering. This PR makes the transformer check for the existence of a project-level `.babelrc`, and if it it's there, it _doesn't_ use the react-native `.babelrc`. This prevents any oddities with Babel plug Closes https://github.com/facebook/react-native/pull/5214 Reviewed By: davidaurelio Differential Revision: D2881814 Pulled By: martinbigio fb-gh-sync-id: 4168144b7a365fae62bbeed094d8a03a48b4798c
32 lines
1.4 KiB
Markdown
32 lines
1.4 KiB
Markdown
# babel-preset-react-native
|
|
|
|
Babel presets for React Native applications. React Native itself uses this Babel preset by default when transforming your app's source code.
|
|
|
|
If you wish to use a custom Babel configuration by writing a `.babelrc` file in your project's root directory, you must specify all the plugins necessary to transform your code. React Native does not apply its default Babel configuration in this case. So, to make your life easier, you can use this preset to get the default configuration and then specify more plugins that run before it.
|
|
|
|
## Usage
|
|
|
|
As mentioned above, you only need to use this preset if you are writing a custom `.babelrc` file.
|
|
|
|
### Installation
|
|
|
|
Install `babel-preset-react-native` in your app:
|
|
```sh
|
|
npm i babel-preset-react-native --save-dev
|
|
```
|
|
|
|
### Configuring Babel
|
|
|
|
Then, create a file called `.babelrc` in your project's root directory. The existence of this `.babelrc` file will tell React Native to use your custom Babel configuration instead of its own. Then load this preset:
|
|
```
|
|
{
|
|
"presets": ["react-native"]
|
|
}
|
|
```
|
|
|
|
You can further customize your Babel configuration by specifying plugins and other options. See [Babel's `.babelrc` documentation](https://babeljs.io/docs/usage/babelrc/) to learn more.
|
|
|
|
## Help and Support
|
|
|
|
If you get stuck configuring Babel, please ask a question on Stack Overflow or find a consultant for help. If you discover a bug, please open up an issue.
|