When it comes to the Chokidar configuration I want to setup the options. I would like to ignore everything except xml files.
{
"path": "C:/... my path ...",
"options": {
"ignored": "everything except xml files",
"persistent": true
}
}
A possible solution would be
Use Chokidar to watch for specific file extension
but is there a way to set the ignored
attribute of the JSON configuration file to "ignore everything except .xml files" instead of setting it by code?
I tried to go for this code
{
"path": "C:/...",
"options": {
"ignored": "!**.xml",
"persistent": true
}
}
const chokidar = require('chokidar');
const { path, options } = require('../fileSystemWatcherConfiguration.json');
module.exports = eventEmitter => {
const watcher = chokidar.watch(path, options);
}
but the watcher.on('add', func)
event gets triggered on each file extension.
It turns out it's actualy preaty simple.
const watcher = chokidar.watch(`${path}/**/*.xml`, options);
By analyzing the package code, we can see that chokidar
uses internaly anymatch to decide if the file should be ignored.
Digging dipper anymatch
uses micromatch and in examples of micromatch
we can see that we can use !
at the begining to negate the math.