使用React-Native运行自定义Babel转换 [英] Run a custom Babel transform with React-Native
问题描述
我需要在React-Native中使用babel-plugin-transform-decorators-legacy
来启用@decorators.如何配置React-Native/Babel使其成为可能?
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?
这与我之前关于如何使@decorators在React-Native中工作的问题有关: https://stackoverflow.com/a/34271636/941058
This is related to my previous question about how to get @decorators working in React-Native: https://stackoverflow.com/a/34271636/941058
推荐答案
使用官方的Babel预设
安装正式的 React Native应用程序的Babel预设:
npm i babel-preset-react-native --save-dev
编辑您的.babelrc
:
{
"presets": ["react-native"]
}
RN v21.0之前的版本:从react-native扩展原始.babelrc
为避免操纵node_modules
目录中的文件,您应该扩展原始.babelrc
.
Prior RN v21.0: Extend the original .babelrc from 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",
}
这篇关于使用React-Native运行自定义Babel转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!