gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Grunt-Watch not running the tasks after few iterations #514

Open kgsnaidu opened 8 years ago

kgsnaidu commented 8 years ago

I have seen many issues which are related to this, but I haven't found the desired solution. Problem : While I am working with sass files or js files in my project, I want to compile/jshint those files when they were changed. So I am using grunt-contrib-watch to do this. It is working fine, but after some files changed, It is tracking the file changes, but It stops compiling( stops running the task, which has to run when the file changes ).

Code :

 grunt.initConfig({
    config: systemConfig(),
    sass: {
        current: {
            options: {
                style: 'expanded',
                lineNumber: true,
                sourcemap: 'none',
                update: true
            }
        }
    }
    jshint: {
        all: []
    },
    watch: {
        sass: {
            files: ['<%= config.PROJECT_DIR %>**/sass/*.scss'],
            tasks: ['sass:current'],
            options: {
                spawn: false,
                debounceDelay: 2000
            }
        },
        js: {
            files: ['<%= config.PROJECT_DIR %>**/js/*.js'],
            tasks: ['jshint'],
            options: {
                spawn: false,
                debounceDelay: 2000
            }
        }
    }
}); 

grunt.event.many('watch', 10, function (action, filepath, target) {
    var paths = new cleanPaths(filepath);
    var filepath = paths.filepath;
    var dirpath = paths.dirpath;
    switch (target) {

    case 'sass':
        if (grunt.file.isMatch(grunt.config('watch.sass.files'), filepath)) {
            grunt.config('sass.current.src', filepath);
            grunt.config('sass.current.dest', filepath.replace('sass/', 'css/').replace('.scss', '.css'));
            pushFile(filepath, filepath.replace('sass/', 'css/').replace('.scss', '.css'));
        }
        break;

    case 'js':
        if (grunt.file.isMatch(grunt.config('watch.js.files'), filepath)) {
            grunt.config('jshint.all', [filepath]);
            pushFile(filepath)
        }
        break;

    default:
        break;
    }
}); 

I am dynamically updating the sass configs( src and dest values).

2016-07-05 18_15_23-sourcetree

Stops compiling even when, there is no error in the sass code.

viceice commented 6 years ago

Same here:

If i then modify grunt configs to force reload it is working again for some time.