最近在研究React Native。感觉开发效率确实不错,但jsx语法写起来感觉不怎么顺手。

试用了Sublime Text 3和Visual Studio Code写代码,感觉反应总是慢一拍。

还是想换回VS2015写jsx,但用VS写jsx好像只能在后缀为.jsx的文件里面写。(不知道VS有没有直接设置在js里写jsx的方法)

于是翻了下react-native的打包程序,改了下让打包程序能自动打包.jsx文件。

贴出修改方法,习惯能VS的可以试着改下

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<exts.length;c++){
        if(null!=exts[c]
              &&this._fastfs.fileExists(potentialModulePath + exts[c])
              &&(file = potentialModulePath + exts[c]))
            break;
      }
      if(!file){
        throw new UnableToResolveError(
          fromModule,
          toModule,
          `File ${potentialModulePath} doesnt exist`,
        );
      }
      //以下为原来的代码
      //if (this._fastfs.fileExists(potentialModulePath)) {
      //  file = potentialModulePath;
      //} else if (this._platform != null &&
      //           this._fastfs.fileExists(potentialModulePath + '.' + this._platform + '.js')) {
      //  file = potentialModulePath + '.' + this._platform + '.js';
      //} else if (this._fastfs.fileExists(potentialModulePath + '.js')) {
      //  file = potentialModulePath + '.js';
      //} else if (this._fastfs.fileExists(potentialModulePath + '.json')) {
      //  file = potentialModulePath + '.json';
      //} else {
      //  throw new UnableToResolveError(
      //    fromModule,
      //    toModule,
      //    `File ${potentialModulePath} doesnt exist`,
      //  );
      //}

  

改成后再运行 react-native start就可以自动打包后缀为.jsx的文件了。

React Native 打包.jsx文件的更多相关文章

  1. [RN] React Native 打包时 减少 Apk 的大小

    React Native 打包时 减少 Apk 的大小 主要有两个方法: 在打包前设置 android\app\build.gradle 文件中 1) def enableProguardInRele ...

  2. React Native之APK文件签名及打包

    生成apk签名文件 我们使用android studio的方式进行签名 AS工具栏找到并点击 build->gennrate signed apk 两种情况: 1.这里如果已经有签名文件了则直接 ...

  3. react native 之上传文件

    最近遇到react native中需要上传一些图片到后台.期间,找了一些第三方上传插件,感觉不太好用,要么只支持一个平台,要么会对其他第三方造成影响,实在无奈.只能直接使用fetch上传.其中上传文件 ...

  4. react native 打包至iphone设备

    1.新建bundle 在自己项目的ios文件夹下新建一个文件夹取名bundle PS:ios文件夹和node_modules文件夹在同一级目录下,这个bundle文件夹名称随意取,后面要用到,但是记得 ...

  5. React Native 打包 Apk

    第一步:生成秘钥库 keytool -genkey -v -keystore opsmart-android-release-key.keystore -alias opsmart-android - ...

  6. react native 的js 文件从哪里获取

    /** * Loading JavaScript code - uncomment the one you want. * * OPTION 1 * Load from development ser ...

  7. react native 打包上架

    https://www.jianshu.com/p/ce71b4a8a246 react-native bundle --entry-file index.ios.js --platform ios ...

  8. react native 打包Ignoring return value of function declared with warn_unused_result attribute

    从 github上下载 项目 用于学习查看别人的代码, 当执行完npm install  用xcode 打开 发现俩个错误提示Ignoring return value of function dec ...

  9. [React Native] 解析JSON文件

    在编写代码时,开发者有时需要存储一些比较多,在应用程序运行时不需要更改的数据.文件大不便于写在代码中,可以把这些数据存储到JSON文件中. 优点非常明显: 1. 数据存放在单独的文件中,代码精简有条理 ...

随机推荐

  1. 编辑距离——Edit Distance

    编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...

  2. hadoop修改MR的提交的代码程序的副本数

    hadoop修改MR的提交的代码程序的副本数 Under-Replicated Blocks的数量很多,有7万多个.hadoop fsck -blocks 检查发现有很多replica missing ...

  3. LINQ之路 6:延迟执行(Deferred Execution)

    LINQ中大部分查询运算符都有一个非常重要的特性:延迟执行.这意味着,他们不是在查询创建的时候执行,而是在遍历的时候执行(换句话说,当enumerator的MoveNext方法被调用时).让我们考虑下 ...

  4. 深入理解IOC模式及Unity框架

    研究了下,有几篇博客确实已经说得很清楚了 1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html  这篇博客是通过一个 ...

  5. django例子,question_text为中文时候报错

    问题描述 UnicodeEncodeError at /admin/polls/question/3/ 'ascii' codec can't encode characters in positio ...

  6. 学习 ---- JavaScript 高级设计程序 第三章(数据类型)

                                    3.4 数据类型 基本数据类型:Undefined.Null.Boolean.Number.String 复杂数据类型:Object 3 ...

  7. .NET开源项目

      综合类 微软企业库 微软官方出品,是为了协助开发商解决企业级应用开发过程中所面临的一系列共性的问题, 如安全(Security).日志(Logging).数据访问(Data Access).配置管 ...

  8. Ioc

    学习过Spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的,今天和大家 ...

  9. python3 不同目录间模块调用

    #Author by Andy #_*_ coding:utf-8 _*_ #__file__获取当前程序的相对路径 import os,sys #print(__file__) # os.path. ...

  10. roundabout插件使用(3d旋转轮播图)兼容IE8

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...