在描述源码路径的时候,经常有一些特殊的奇怪的要求。Grunt 通过内建的 node-globminimatch 库提供了文件名的扩展机制。

常见的通配符如下:

  • * 匹配除了 / 之外的任意数量的数字和字符
  • ? 匹配除了 / 之外的单个字符
  • ** 匹配任意数量的字符,包括 /,这样可以包含任意级的路径
  • {} 提供一个以逗号 (,) 分割的或表达式列表
  • ! 放在表达式的开头表示取反

比如,foo/*.js 将会匹配 foo/ 文件夹下面的所有 .js 扩展名的文件,而 foo/**/*.js 则会匹配在 foo/ 目录下任意级别子目录中的 .js 扩展名的文件。

使用 ! 来不包含特定的文件,需要注意的是 ! 需要是路径的第一个字符。

为了更加简单地通配符,Grunt 允许使用数组来表示通配符。Grunt 将会安装顺序处理,返回的结果是唯一的。

例如

// You can specify single files, 简单文件名:
{src: 'foo/this.js', dest: ...}
// Or arrays of files, 使用数组表示多个文件名:
{src: ['foo/this.js', 'foo/that.js', 'foo/the-other.js'], dest: ...}
// Or you can generalize with a glob pattern, 使用通配符:
{src: 'foo/th*.js', dest: ...} // This single node-glob pattern, 单个通配符:
{src: 'foo/{a,b}*.js', dest: ...}
// Could also be written like this, 通过数组,使用多个通配符:
{src: ['foo/a*.js', 'foo/b*.js'], dest: ...} // All .js files, in foo/, in alpha order, 所有的 .js 文件,按照字符顺序:
{src: ['foo/*.js'], dest: ...}
// Here, bar.js is first, followed by the remaining files, in alpha order, 第一个是 bar.js, 其它文件按字母顺序 :
{src: ['foo/bar.js', 'foo/*.js'], dest: ...} // All files except for bar.js, in alpha order, 除了 bar.js 之外的文件,按字母顺序:
{src: ['foo/*.js', '!foo/bar.js'], dest: ...}
// All files in alpha order, but with bar.js at the end, 所有文件按照字母顺序,bar.js 在最后.
{src: ['foo/*.js', '!foo/bar.js', 'foo/bar.js'], dest: ...} // Templates may be used in filepaths or glob patterns, 可以嵌入表达式:
{src: ['src/<%= basename %>.js'], dest: 'build/<%= basename %>.min.js'}
// But they may also reference file lists defined elsewhere in the config, 引用其它地方定义的文件列表:
{src: ['foo/*.js', '<%= jshint.all.src %>'], dest: ...}

更多信息可以见 node-globminimatch 的文档。

最新文章

  1. 如何自适应网页的协议(http/https/……)
  2. 微信支付:redirect-uri参数错误 的解决办法
  3. JAVA关系运算符
  4. Apache Spark Tachyon的简介
  5. SpringMVC通过注解获得参数
  6. 使用CodeFirst实现动态建库
  7. 599. Minimum Index Sum of Two Lists
  8. C语言博客作业—函数嵌套调用
  9. 【prufer编码+组合数学】BZOJ1005 [HNOI2008]明明的烦恼
  10. Numerical Analysis
  11. 傻瓜式搭建私人网络硬盘——owncloud安装指南
  12. Python3 与 NetCore 基础语法对比(Function专栏)
  13. Unity 2017 Game Optimization 新版
  14. Linux命令之nl命令
  15. VMWare VSphere6.0的实验笔记
  16. c# 进程调用exe
  17. .Net高级技术——结构体
  18. 总结:从Node爬取数据到前端图表展示
  19. h5中video的一些坑
  20. iOS学习之NSString

热门文章

  1. 内容模块PC标签调用说明
  2. JSP的Servlet监听器
  3. C++ Socket编程步骤 【转】
  4. 更改AD查询LDAP条目的1000限制
  5. C基础--结构体成员初始化方式
  6. S3C2440之MMU
  7. JavaScript-CheckBox全选/反选
  8. Jedis 连接redis超时
  9. 重新认识Entity Framework
  10. Going Home (hdu 1533 最小费用流)