我有这样的项目结构:
.
├── index.js
└── bootstrap/
├── css/
│ ├── style.css
│ └── fake.js
└── js/
└── index.js
我正在尝试查找bootstrap文件夹下的所有JS文件,忽略css文件夹。我使用下面的glob代码:
index.js
const { globSync } = require('glob');
const files = globSync([`./bootstrap/**/*.js`], {
ignore: [`bootstrap/css/**`],
});
files.forEach(file => {
console.log(file); // outputs bootstrap/js/index.js
})
它按预期工作,并且由于ignore属性,仅检索bootsrap/js目录下的JS文件。
但是如果我把ignore属性改为相对路径
ignore: [`./bootstrap/css/**`],
它不再排除css文件夹:
const { globSync } = require('glob');
const files = globSync([`./bootstrap/**/*.js`], {
ignore: [`./bootstrap/css/**`],
});
files.forEach(file => {
console.log(file); // outputs bootstrap/js/index.js and bootstrap/css/fake.js
})
有什么问题吗?为什么我不能使用相对路径忽略属性?
1条答案
按热度按时间wgmfuz8q1#
glob
软件包感觉过时了,在新版本的node上不能像预期的那样工作。较新的代码使用fast-glob
,它可以使用ignore
和否定模式:https://replit.com/@silentmantra/Glob-Test#index.js