Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt watch not running less after error correction

I've got an issue with Grunt Watch currently not re-running tasks after compilation error correction.

I get the error message, but then after correcting the error, grunt says the file has been changed, but no tasks are run after that point.

Grunt file:

watch: {
        less: {
            files: ['public/assets/less/**/*.less'],
            tasks: ['css'],
            options: {
                atBegin: true,
                nospawn: true
            }
        },
        scripts: {
            files: [
                'public/assets/js/homepage.js'
            ],
            tasks: ['jsApp'],
            options: {
                nospawn: true,
            }
        }
    },

Error log:

>> ParseError: Unrecognised input in public/assets/less/template.less on line 114, column 31:
>> 114         @media screen and (max-width: 767px) {
>> 115             left: 0;
Warning: Error compiling public/assets/less/main.less
// ----- Corrected the file here, saved again -----
>> File "public/assets/less/template.less" changed.

End of file. Nothing after this point.

like image 673
Matt Cavanagh Avatar asked May 06 '16 08:05

Matt Cavanagh


2 Answers

This is a problem with the grunt-contrib-watch package spawn function, you probably want to remove nospawn. You might want to try version 1.0.0 of grunt watch if you have not already.

This issue has been discussed before https://github.com/gruntjs/grunt-contrib-watch/issues/58

Also, note the documentation:

Not spawning task runs can make the watch more prone to failing so please use as needed.

In your position I would upgrade first, see that I have the latest version of grunt, grunt watch and grunt less. If that wouldn't solve the problem I would just let it spawn normally.

like image 124
Oli Avatar answered Oct 17 '22 01:10

Oli


You can just simplify your file like this:

//src ===============================
                var src;
                config.src = src = {
                     libFolder       : 'lib/**/*.js',
                     lessFolder      : 'less/**/*.less',

                };

//Watch ===============================
                config.watch = {
                     scripts: {
                        files: ["<%= src.libFolder %>", "<%= src.lessFolder %>"]
                        ,tasks: ["dev", "less:dist"]

                     }
                }

you need to insert the tasks and files to be watched:

in that case above grunt watching all files from lib and less folder, if I do any change there grunt will run the task.

as well you need insert the tasks there to be run until you stop grunt watch.

in that case I am running dev ans less:dist at the same time.

on dev I am running: 'sprite','imagemin','concat:dev', 'uglify' ,

grunt.registerTask('dev',['sprite','imagemin','concat:dev', 'uglify']);

so I inserted this task in grunt watch, so grunt will be watching running all tasks with no error.

I hope this helped you.

like image 1
raduken Avatar answered Oct 17 '22 02:10

raduken