如何在电子应用程序中观看文件?

我想使用Chokidar在我的应用程序中观看文件。 问题是,当你尝试实例化chokidar.watch时,电子会抛出一个错误。 我想知道这是否是一个已知的兼容性问题,以及是否有内置的解决scheme来解决这个问题。 Google迄今为止没有在电子应用程序中观看文件。 只有使用chokidar对象时才会出现错误。 要求它不会导致问题。

我的代码在渲染过程如下。 注释掉var观察者代码将完全消除控制台错误。 代码直接来自他们的文档。

var chokidar = remote.require('chokidar'); chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', function(event, path) { console.log(event, path); }); 

控制台错误:

 Uncaught Error: criterion.test is not a function TypeError: criterion.test is not a function at testCriteria (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:29:26) at Array.some (native) at anymatch (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:59:48) at EventEmitter.FSWatcher._isIgnored (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:221:15) at EventEmitter.NodeFsHandler._addToNodeFs (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/lib/nodefs-handler.js:429:12) at EventEmitter.<anonymous> (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:410:12) at /Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:16:7 at Array.forEach (native) at each (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:15:11) at EventEmitter.FSWatcher.add (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:409:5) 

任何关于如何添加观看我的项目的build议非常感谢。 Atom编辑器检测使用文件浏览器添加文件和文件夹的时间,并在侧边栏中适当地显示最新的文件夹信息。 如果primefaces可以做到这一点,我的应用程序也可以!

这可能会打破电子远程对象的所有规则 – 但是您可以尝试访问远程版本的chokidar

 var chokidar = global\['require'\]('remote').require('chokidar');