问题描述
在JavaScript世界中,我是一个新手,我正在尝试学习和理解React Native.
I am new pretty new in Javascript world and I am trying to learn and understand React Native.
为什么要在这么多的本机样板中找到babel和webpack?( https://github.com/jhabdas/react-native-webpack-starter-kit )
如果我正确理解babel是用于支持较旧的浏览器,但我不使用带有react-native的浏览器. RN不会将所有js代码都编译为本地代码吗?
If I understand correctly babel is for supporting older browsers but I am not using a browser with react-native. RN doesn't compile all js code to native?
与webpack相同-如果我的js文件无论如何都是由RN编译的,为什么还要将它们捆绑在一起?
Same thing with webpack - why would I need to bundle my js files if they are getting compiled by RN anyways?
推荐答案
react-native已包含Babel,因此您可以选择以ES6 +或更旧的ES5风格编写.
Babel is already included with react-native so you have the option of either writing in ES6+ or the older ES5 style.
为了明确起见,React-native在移动设备上的 javascript核心上运行,在浏览器中,但仍呈现JS代码,因此babel介于两者之间,使您可以编写下一代JS代码并使用React的JSX代码.
To clarify, React-native runs on the javascript core on mobile, this means its not in a browser but still renders the JS code so babel is there, in-between, to allow you to write next gen JS code and use React's JSX code.
这是列表支持的ES6 +功能
Here is a list of supported ES6+ features
有些人想要的不是Babel的,带有react-native的附加功能,所以最终使用webpack和自定义Babel配置.最近,他们增加了对异步功能(ES7)之类的支持,所以就我个人而言,除非您有非常特殊的需求,否则我不认为您需要走webpack路线.
Some people want additional features not in Babel that ships with react-native so they end up using webpack and custom Babel configurations. Recently they've added support for things like async functions (ES7) so personally, i don't think you need to go the webpack route unless you have a very specific need.
这篇关于React Native-为什么我需要babel或webpack?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!