Hi all
I have used this lib before, coming here again, I am looking for an include / exclude scheme to watch certain file patterns. All I see is the ignore option.
If ignore is the only option, I can handle that, but it would be really nice to see an example of how to "ignore all but". For example, I want to ignore all files except those that end with ".tsx". How can I do that with this lib / anymatch and the ignore option?
It would be nice to have some clarification on this in the docs. I went through the issues and didn't see anything on this.
I am about to try this:
ignored: /\.[^tsx]$/,
last time I checked 3 or 4 months ago, I don't believe this lib accepted regexes for the ignored option, but now one example in the readme shows regex usage, so imma try it.
yeah that regex didn't work, either because the regex is malformed (doesn't do what I intended it to do) or chokidar/anymatch doesn't support a regex as such, looking for help thanks
The regex you showed will not work because the [^tsx] is not doing what you were intending. It currently is set to match a string ending in a period, then a single character that is anything other than t, s, or x. If you crafted a regex that matched the file paths you wanted ignored and did not match the ones you wanted included, then you could use that as your ignored setting.
You can't give ignored a negated pattern and nothing else, at that point just un-negate it and use it as your watch pattern.
If you give an array of glob patterns including a negated one, giving anymatch something to actually match along with something to negate, that could work too.
ignored: ['!**/*.tsx', '**']
I'm trying to do something like this but with more extensions, I would like only mp4 and mpg extensions to trigger the change, how can I accomplish that?
Found the answer here https://stackoverflow.com/questions/40468608/use-chokidar-to-watch-for-specific-file-extension. In case anyone needs this. And if we need to specify more extensions just replace *.xml with *.{xml,html}
Found the answer here https://stackoverflow.com/questions/40468608/use-chokidar-to-watch-for-specific-file-extension. In case anyone needs this. And if we need to specify more extensions just replace
*.xmlwith*.{xml,html}
Are you sure it works? I was unable to make it work.
It would be more user-friendly to add a configuration property called 'included' that takes an array of accepted file types than to have to come up with a pattern match.
There's a related answer on _StackOverflow_: https://stackoverflow.com/a/44661192/5017391
const watchedFileTypes: string[] = ['jpg', 'png', 'gif'];
// create a list like ["C:/pics/**/*.jpg", "C:/pics/**/*.png", ...] for chokidar
function buildWildcardList(path: string): string[] {
const result: string[] = [];
watchedFileTypes.forEach((extension: string) => {
result.push(path + '/**/*.' + extension);
});
return result;
}
this.watcher = chokidar.watch(buildWildcardList('C:/pics'), watchOptions);
Unsure how performant it is to watch many file types rather than a single directory 🤷♂️
ps - in watchOptions make sure that disableGlobbing is not true 👌
Most helpful comment
It would be more user-friendly to add a configuration property called 'included' that takes an array of accepted file types than to have to come up with a pattern match.