React Native 如何运行打包.jsx文件

最近在学习RN,发现项目里面的.jsx文件怎样都无法引用,后来网上搜索了一下,发现RN无法运行.jsx文件。在网上搜索到一位大神的博客,描述了如何让RN运行打包.jsx文件,copy一份作为记录,源博客链接:http://www.cnblogs.com/Grart/p/5033281.html

1.项目主文件夹\node_modules\react-native\packager\react-packager\src\Server\index.js找"var watchRootConfigs = opts.projectRoots.map(dir => {"这段,加上'.jsx'

var watchRootConfigs = opts.projectRoots.map(dir => {
return {
dir: dir,
globs: [
'**/*.js',
'**/*.json',
'**/*.jsx',
].concat(assetGlobs),
};
});

2. 项目主文件夹\node_modules\react-native\packager\react-packager\src\DependencyResolver\DependencyGraph\index

0.22版使用的是node-haste在\node_modules\react-native\node_modules\node-haste\lib\index

找"this._crawling = crawl(allRoots, {"加段,同样加上'jsx'

this._crawling = crawl(allRoots, {
ignore: this._opts.ignoreFilePath,
exts: ['js', 'jsx','json'].concat(this._opts.assetExts),
fileWatcher: this._opts.fileWatcher,
});

3.项目主文件夹\node_modules\react-native\packager\react-packager\src\DependencyResolver\DependencyGraph\ResolutionRequest.js

0.22版在\node_modules\react-native\node_modules\node-haste\lib\DependencyGraph
找"if (this._fastfs.fileExists(potentialModulePath)) {"改成

let file;
let exts=["",
    this._platform?('.' + this._platform + '.js'):null,
    '.js',
    '.json',
    '.jsx'];
for(let c=0;c


你可能感兴趣的:(react-native)