Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add delay to Grunt Watch for Less files

I'm using Grunt for compiling Less files on a server, the problem is when I upload the less file over the server using FTP client (Filezilla), the Grunt --watch task starts to compiling the less file from the very first byte that it receives before letting it to finish uploading completely, which cause the CSS file to be empty.

I need to be able to upload the file fully on the server then the Grunt Watch does its job, so I thought if there's a command to give Grunt a timeout delay like 2 seconds then start the task.

like image 391
Sohail Avatar asked Dec 18 '25 11:12

Sohail


1 Answers

You can get a similar effect by letting watch trigger instantly but then triggering a wait task (from grunt-wait plugin) before your less task, something along the lines of:

less: {
    dist: {
        files: [{
            expand: true,
            cwd: 'yourdir',
            src: '*.less',
            dest: 'destdir',
            ext: '.css'
        }]
    }
},

wait: {
    ftp: {
        options: {
            delay: 2000
        }
    }
},

watch: {
    less: {
        files: ['yourdir/*.less'],
        tasks: ['wait:ftp', 'less:dist']
    }
},
like image 191
Xavier Priour Avatar answered Dec 21 '25 04:12

Xavier Priour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!