匹配输出文件/目录库路径globby库

专门用来匹配文件和目录然后输出路径的库,是扩展于glob库
glob:https://github.com/mrmlnc/fast-glob#options-3
globby:https://github.com/sindresorhus/globby#readme

1、下载
	cnpm install -D globby

2、使用
	const globby = require('globby');
	
	异步(Promise方式):
		const res=await globby(['要处理的文件正则表达式','可以有多个'],{
			dot:true,  匹配.开头的路径
		})
		
		匹配正则格式(大部分符合js正则规范):
			匹配的路径只能是'/'而不能是'\',path.posix.join可将'\'变成'/',path.posix.join('ww'.'aa\bb'); 但是aa\bb里的\会被忽略
			*		匹配除斜杠(路径分隔符)、隐藏文件(以.开头的名称)之外的所有内容。
			**		匹配零个或多个目录。
			?		匹配除斜杠(路径分隔符)以外的任何单个字符。
			[[:digit:]]	匹配数字
			(a|b)	匹配a或b
			例子:
			    src/**/*.js — matches all files in the src directory (any level of nesting) that have the .js extension.
			    src/*.?? — matches all files in the src directory (only first level of nesting) that have a two-character extension.
			    file-[01].js — matches files: file-0.js, file-1.js.
			    src/**/*.{css,scss} — matches all files in the src directory (any level of nesting) that have the .css or .scss extension.
			    file-[[:digit:]].js — matches files: file-0.js, file-1.js, …, file-9.js.
			    file-{1..3}.js — matches files: file-1.js, file-2.js, file-3.js.
			    file-(1|2) — matches files: file-1.js, file-2.js.

		参数:
			 
		
	
	同步:
		globby.sync(...)

代码示例:

  const absPath=path.isAbsolute(from) ? from : path.posix.join('D:/webpack_code/webpack4/webpack_自定义',from);

  //读取from中除了忽略的文件
  const res = await globby([absPath], { ignore:'**/index.html'})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值