在 React-Native 中使用 ES7 静态 propTypes [英] Using ES7 static propTypes with React-Native
本文介绍了在 React-Native 中使用 ES7 静态 propTypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 React-Native 默认打包器启动我的项目时,出现此错误:Unexpected token
在这一行:
When I'm launching my project using React-Native default packager, I have this error: Unexpected token
on this line:
static propTypes = {
/// ...
};
我在 GitHub 上查看了 React-Native 问题,但没有找到解决方案.
I took a look on React-Native issues on GitHub, but I didn't find a solution.
有什么建议吗?
推荐答案
@Fomahaut 回答后,我一直在 Facebook 的 GitHub 仓库上找,发现了这个问题:https://github.com/facebook/react-native/issues/2182
After @Fomahaut answer, I keep looking on Facebook's GitHub repository and found this issue: https://github.com/facebook/react-native/issues/2182
- 在项目根目录下创建一个 .babelrc 文件
- 向 Babel 添加更多规则
示例:
{
"retainLines": true,
"compact": true,
"comments": false,
"whitelist": [
"es6.arrowFunctions",
"es6.blockScoping",
"es6.classes",
"es6.constants",
"es6.destructuring",
"es6.forOf",
"es6.modules",
"es6.parameters",
"es6.properties.computed",
"es6.properties.shorthand",
"es6.spread",
"es6.tailCall",
"es6.templateLiterals",
"es6.regex.unicode",
"es6.regex.sticky",
"es7.asyncFunctions",
"es7.classProperties",
"es7.comprehensions",
"es7.decorators",
"es7.exponentiationOperator",
"es7.exportExtensions",
"es7.functionBind",
"es7.objectRestSpread",
"es7.trailingFunctionCommas",
"regenerator",
"flow",
"react",
"react.displayName"
],
"sourceMaps": false
}
这篇关于在 React-Native 中使用 ES7 静态 propTypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文