Does React Native use Babel by default or is it just one option?

3.5k views Asked by At

I know there is some sort of relationship between React Native and Babel.

What I'm not sure of is whether it's just there if I want to use it and I must enable it somehow, or whether RN always transpiles with Babel.

It must be transpiling one way or another since RN uses JSX, which is not native to any JS engine.

That makes me think it's unlikely that there would be multiple transpilation paths, one for just JSX and one for the Babel+JSX combo.

The reason I ask is because I found a newish JS function String.fromCodePoint() that works on Android but not iOS.

Is this because the transpilation doesn't try to cover all modern JS features? Because it's a bug I should report? Something that the regular React Native transpiler doesn't handle but the Babel one would?

What exactly is the magnitude of my misunderstanding? (-:

1

There are 1 answers

2
Gershon Papi On BEST ANSWER

Your'e right. React Native does get transpiled using Babel. You can see here all the babel transformers used for react native.

I don't believe you can avoid using babel, but if you wish to add transformers and plugins, you could, using you own .babelrc file. However, you'd still need the transformers which React Native uses, so to make it easier you could just use the react-native babel preset, which bundles for you all the transformers required by react-native. Additional transformers you would need to install and configure on your own.