解决React-Native reload后代码不更新问题

使用React-Native开发app也会火起来。我们在真机上面调试是需要实时更新代码,让代码生效的。一般来说我们会设置Enable Hot Reloading【轻轻摇晃手机就可以设置】。但是有时候我们修改了代码,在手机上并不会实时更新代码。

解决的办法就是打开文件
app_name\node_modules\react-native\node_modules\node-haste\lib\FileWatcher\index.js
修改变量MAX_WAIT_TIME:

// var MAX_WAIT_TIME = 120000;
var MAX_WAIT_TIME = 360000;

修改部分代码:

key: '_createWatcher',
    value: function _createWatcher(rootConfig) {
      var watcher = new WatcherClass(rootConfig.dir, {
        glob: rootConfig.globs,
        dot: false
      });

      return new Promise(function (resolve, reject) {

        const rejectTimeout = setTimeout(function() {
          reject(new Error([
            'Watcher took too long to load',
            'Try running `watchman version` from your terminal',
            'https://facebook.github.io/watchman/docs/troubleshooting.html',
          ].join('\n')));
        }, MAX_WAIT_TIME);

        watcher.once('ready', function () {
          clearTimeout(rejectTimeout);
          resolve(watcher);
        });
      });
	}

猜你喜欢

转载自blog.csdn.net/new_Aiden/article/details/52001790