简体   繁体   中英

Gruntjs - watch for changes in a large amount of subdirectories and files

I just started using grunt.js recently and I wanted to know if it is possible to watch for changes in large folder structures?

it works fine for me in small project folder structures but when trying to watch a whole system like magento or wordpress or even parts of them it just hangs there and doesn't find any changes.

am I doing something wrong?

here's my gruntfile.js:

module.exports = function(grunt) {
grunt.initConfig({
    watch: {
        livereload: {
            files: ['template/{,*/}*'],
            options: {
                // Start a live reload server on the default port 35729
                livereload: true
            }
        }
    }
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', 'watch');
}

if you are familiar with magento, the gruntfile sits in

D:\\wamp\\www\\magento\\app\\design\\frontend\\myTheme\\default\\

and looks in the 'template' folder and onward for files changes.

there are 404 files and 242 folders inside the 'template' folder. it isn't that much to be fair... I don't understand why it doesn't find the changes almost immediately and just hangs.

when adding just a single subdir (ex: /page contains 25 Files and 4 Folders) to the gruntfile files source reference it finds the changes instantly.

example:

files: ['template/page/{,*/}*']

I hope I managed to pass my question clearly enough. if something isn't clear please let me know.

Thank you for your time!

Ok I found the solution. the problem was with the regular expression I used.

files: ['template/page/{,*/}*']

should have been:

files: ['**/*.*']

to match any file in any sub directory.

and:

files: ['template/**/*.*']

to match all sub directories and files within the 'template' folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM