【问题标题】:Add delay to Grunt Watch for Less files为 Grunt Watch 添加延迟以获取更少的文件
【发布时间】:2015-06-06 13:31:21
【问题描述】:
我正在使用 Grunt 在服务器上编译 Less 文件,问题是当我使用 FTP 客户端 (Filezilla) 在服务器上上传 less 文件时,Grunt --watch 任务开始从非常它在完成上传之前收到的第一个字节,这会导致 CSS 文件为空。
我需要能够将文件完全上传到服务器上,然后 Grunt Watch 才能完成它的工作,所以我想如果有一个命令可以给 Grunt 一个像 2 秒这样的超时延迟然后启动任务。
【问题讨论】:
标签:
gruntjs
less
grunt-contrib-watch
【解决方案1】:
您可以通过让 watch 立即触发但随后在您的 less 任务之前触发 wait 任务(来自 grunt-wait 插件)来获得类似的效果,类似于:
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']
}
},