简体   繁体   中英

chokidar ignore everything except xml files

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.

Update

It turns out it's actualy preaty simple.

const watcher = chokidar.watch(`${path}/**/*.xml`, options);

Old answer

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM