I need to use babel-plugin-transform-decorators-legacy
with React-Native to enable @decorators. How does one configure React-Native / Babel to make this possible?
This is related to my previous question about how to get @decorators working in React-Native: https://stackoverflow.com/a/34271636/941058
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 babel. config. js file in your project's root directory, you must specify all the plugins necessary to transform your code.
You can create our own “. babelrc” file at the root of your project. To make sure that you use the default babel configuration that comes with React Native, install babel-preset-react-native. On top of this you have to install another module: codegen.
babelrc in your react native folder in your node_modules folder. This file: react-native/packager/react-packager/. babelrc. Put it before the syntax-class-properties.
Install the official Babel presets for React Native applications:
npm i babel-preset-react-native --save-dev
Edit your .babelrc
:
{
"presets": ["react-native"]
}
To avoid manipulating files in the node_modules
directory, you should extend the original .babelrc
.
By keeping your dependencies clean, there won't be any issues with upgrades or sharing the project.
{
"extends": "react-native/packager/react-packager/.babelrc",
}
You would install the plugin at your projects root level then add the plugin to the .babelrc in node_modules/react-native/packager/react-packager/.babelrc
The issue with this work around to using @decorators is if you are working on a team for the app every developer will need to make the change to .babelrc since node_modules should not be checked into source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With