68

My code folders and files are like this, you never know how many sub folders in it:

js/sub1/a.js
js/sub2/b.js
js/sub3/sub31/c.js
js/sub4/sub41/sub411/d.js

Here is part of the Gruntfile.js:

grunt.initConfig({
    watch: {
        src: {
            files: ['js/*.js'],
            tasks: []
        }
    }
});

Grunt can't watch the changes of my all JavaScript files by using 'js/*.js'. So how to write the correct file path expression?

starball
  • 20,030
  • 7
  • 43
  • 238
HOT.CHO
  • 769
  • 2
  • 6
  • 7

1 Answers1

166

Per the official documentation on file globbing, to watch for changes for files of a certain file type in the directory path and its subdirectories, you'll want:

files: ['js/**/*.js']
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
ashox
  • 1,701
  • 1
  • 11
  • 3
  • 14
    one thing I noticed - you have to re-run `grunt watch` if you add some files to these paths and its more than a few levels deep – Erin Drummond Oct 01 '14 at 23:20