1

我有这个目录结构

├── components
│   ├── quarks
│   │   └── index.js
│   │   └── ...
│   ├── bosons
│   │   └── index.js
│   │   └── GridLayout.vue
│   │   └── ...
│   ├── atoms
│   │   └── ButtonStyle.vue
│   │   └── InputStyle.vue
│   │   └── index.js
│   │   └── ...
│   ├── .......
└─────

我想忽略index.js每个文件夹中的,但我没有得到它,我已经尝试了多种方式

const path = require('path')
const chokidar = require('chokidar')
const ROOT_PATH = path.resolve('components')

const watcher = chokidar.watch(ROOT_PATH, {
  ignored: ROOT_PATH + '/*/index.js', //does not work
  ignoreInitial: true
})

已经试过了: './components/**/index.js', './components/*/index.js', 'components/*/index.js', 'components/**/index.js', 'ROOT_PATH + '/**/index.js'

任何人都知道如何使它工作?

4

3 回答 3

0

chokidar 文档指定该参数ignored是可任意匹配的,因此可以通过多种方式完成。

这是一个正则表达式解决方案......

任何index.js文件,即使在根文件夹中:

{
    ignored: /(^|[\/\\])index\.js$/,
    // ...
}

index.js在子文件夹中的文件:

{
    ignored: /[\/\\]index\.js$/,
    // ...
}

另请注意,在您的示例中,您使用signoreInitial这不是一个选项,也许您的意思是ignoreInitial


或者使用回调:

{
    ignored: (path) => { return path.endsWith('\\index.js') || path.endsWith('/index.js'); },
    // ...
}
于 2019-07-07T22:17:43.557 回答
0

在 Mac 上对我有用的是**

ignored: ['**/node_modules'],

因此,如果其他选项由于错误而不起作用,请选择以下选项:

 ignored: ['**/index.js'],
于 2021-07-07T13:25:26.860 回答
0

Chokidar 似乎有问题,忽略 MacOS 上的文件有缺陷,这就是我的印象。

因此,在运行我的操作之前,我正在检查文件是否与我想忽略的文件相同。

chokidar
  .watch('components', { ignoreInitial: true })
  .on('all', (event, filename) => {
    filename !== 'index.js'
    // action here
  })
于 2019-07-09T16:03:28.227 回答