grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

Grunt-Watch not running the tasks after few iterations

Open kgsnaidu opened this issue 8 years ago • 1 comments

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.

kgsnaidu avatar Jul 05 '16 14:07 kgsnaidu

Same here:

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

viceice avatar Sep 13 '17 14:09 viceice