Sohail
Sohail

Reputation: 548

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.

Upvotes: 3

Views: 425

Answers (1)

Xavier Priour
Xavier Priour

Reputation: 2121

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']
    }
},

Upvotes: 1

Related Questions