跳到主要内容

glob

一、认识


glob 用于匹配指定目录下的文件

二、语法


2.1 同步匹配

const glob = require("glob");

function toUnitPath(path) {
return path.replace(/\\/g, "/");
}

const files = glob.sync(`${toUnitPath(__dirname)}/**/*.js`, { nodir: true });

console.log(files);


// 结果:

// [
// 'D:/Practice/Webpack/webpack-plugin/glob/1.js',
// 'D:/Practice/Webpack/webpack-plugin/glob/2.js',
// 'D:/Practice/Webpack/webpack-plugin/glob/glob.js'
// ]