Search code examples
javascriptgruntjsfile-globs

grunt file glob file extension pattern


I have a grunt task to traverse a folder structure for all jpg, jpeg and png files. Is there an easier way to do this compared to

images : {
    expand : true,
    flatten : true,
    cwd : "develop/",
    src : ["modules/**/*.jpg", "modules/**/*.jpeg", "modules/**/*.png"],
    dest : "build/resources/img/"
},

According to the documentations, the { .. } bracket for a file allows multiple options to be compared with for the containing files. However, the following do not work for src array values:

"modules/**/*{jpg, jpeg, png}"
"modules/**/*.{jpg, jpeg, png}"
"modules/**/*{.jpg, .jpeg, .png}"

and so therefore I was forced to do a straight glob pattern for each file extension


Solution

  • There's extra spaces after the commas in your expression.

    This should do it: "modules/**/*.{jpg,jpeg,png}"