[英]Ignore multiple files with Chokidar
Is there any way to ignore multiple files or directories when watching directory with Chokidar? 使用Chokidar观看目录时,有什么方法可以忽略多个文件或目录?
My code: 我的代码:
var ignoredFiles = ['c:/test/file1.txt', 'c:/test/file2.txt'];
//var ignoredFiles = 'c:/test/file1.txt';
var watchOptions: WatchOptions = <WatchOptions>{
ignored: ignoredFiles,
persistent: true,
ignoreInitial: false,
awaitWriteFinish: false,
ignorePermissionErrors: false
};
this.watcher = chokidar.watch('c:/test', watchOptions);
If I try to set ignored option to array of strings, it doesn't work. 如果我尝试将忽略选项设置为字符串数组,则无法使用。 Moreover, even if I try to set it to string, it doesn't work either.
而且,即使我尝试将其设置为字符串,它也不起作用。
Any suggestions about a simple way of doing that? 关于这样做的简单方法有什么建议吗? From Chokidar docs:
来自Chokidar文档:
ignored: (anymatch-compatible definition) Defines files/paths to be ignored.
被忽略:(任何匹配匹配的定义)定义要忽略的文件/路径。 The whole relative or absolute path is tested, not just filename.
测试了整个相对或绝对路径,而不仅仅是文件名。 If a function with two arguments is provided, it gets called twice per path - once with a single argument (the path), second time with two arguments (the path and the fs.Stats object of that path).
如果提供了具有两个参数的函数,则每个路径将调用两次-一次使用单个参数(路径),第二次使用两个参数(路径和该路径的fs.Stats对象)。
Thank you. 谢谢。
Various options for ignored 忽略的各种选项
var ignoredFiles = ['c:/test/file1.txt', 'c:/test/file2.txt'];
var watchOptions = {
ignored: ignoredFiles,
persistent: true,
ignoreInitial: false,
awaitWriteFinish: false,
ignorePermissionErrors: false
};
this.watcher = chokidar.watch('c:/test', watchOptions);
or else 要不然
ignored: /file/, // ignores files and dirs which contain "file" in the name
You can also use regular expressions 您还可以使用正则表达式
ignored: /file[1-2]\.txt/, // ignores files matching this regex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.