如何在React Native中要求JSX?
var MyScreen = require('./apps/screens/LoadingScreen');
以这种方式需要.js文件,但找不到.jsx文件。
发布于 2015-06-19 03:55:47
我认为您可能只需要将文件从.jsx重命名为.js,构建过程将负责所有转换。科林的回答似乎证实了这一点。
http://moduscreate.com/react-native-has-landed/中显示了一个.js文件中的JSX示例。
React团队继续鼓励使用JSX:http://facebook.github.io/react/docs/jsx-in-depth.html。
发布于 2015-12-29 09:09:10
下面是我用一个快速技巧解决这个问题的方法:打开[YOU_PROJECT_FOLDER]/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/index.js并编辑55行,如下所示
extensions: extensions || ['jsx', 'js', 'json'],open [YOU_PROJECT_FOLDER]/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js和后面的第333行添加以下两行:
} else if (this._fastfs.fileExists(potentialModulePath + '.jsx')) {
file = potentialModulePath + '.jsx';当您执行类似require("mymodule")的操作时,这将使打包程序识别mymodule.jsx文件
注意:实际行来自最新的0.17版本,在其他版本中这些行可能有所不同
发布于 2015-06-11 20:28:46
我可能错了,但是在搜索了一下源代码之后,似乎只支持js和json:
this._moduleExtPattern = new RegExp(
'\.(' + ['js', 'json'].concat(this._assetExts).join('|') + ')$'
);这个问题似乎支持这一点:
https://stackoverflow.com/questions/30685892
复制相似问题