【问题标题】:How to match html or js once in minimatch?如何在 minimatch 中匹配一次 html 或 js?
【发布时间】:2016-10-20 10:41:48
【问题描述】:

我正在为 gulp watch 编写 glob 模式,并希望在每次 html 或 js 更改时重建

# my first variant
> minimatch('src/app/app.js', 'src/app/**/*.(js|html)')
false # not working
> minimatch('src/app/app.js', 'src/app/**/*.+(js|html)')
true # this works
> minimatch('src/app/app.jsjs', 'src/app/**/*.+(js|html)')
true
# but also this works:
> minimatch('src/app/app.jsjsjsjsjs', 'src/app/**/*.+(js|html)')
true

如何正确地做,意味着只匹配一次html或js,就像在正则表达式中一样?

【问题讨论】:

    标签: javascript node.js glob


    【解决方案1】:

    看起来你可以使用这个:

    minimatch('src/app/app.js', 'src/app/**/*.{js,html}')
    

    【讨论】:

      【解决方案2】:

      你要求它匹配一个或多个(.js|.html),你需要使用@来匹配一个

      minimatch('src/app/app.js', 'src/app/**/*.@(js|html)')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-27
        • 1970-01-01
        • 1970-01-01
        • 2022-10-02
        相关资源
        最近更新 更多