0

我正在使用grunt-watch重新构建较少的样式表:

    watch: {
        less: {
            files: ['media/less/**/*.less'],
            tasks: ['less'],
            options: {
                atBegin: true,
                spawn: false
            }
        }
    }

但是,如果任何文件中存在语法错误,任务就会循环,尝试每秒.less重新构建文件......这使得调试相当困难,因为错误消息很快就会滚动过去。.less

有什么办法可以解决这个问题,所以只有在文件再次更改后grunt-watch才会重新运行任务?.less

这是使用:

grunt@0.4.2
grunt-contrib-less@0.8.3
grunt-contrib-watch@0.5.3
4

2 回答 2

2

我认为您描述的问题是this one,它已在 master 中修复但尚未发布(截至 2013/12/17)。

于 2013-12-17T15:01:41.660 回答
0

less好吧,出于调试目的,您可以使用自定义任务对任务进行简单的封装:

grunt.registerTask('myless', 'my less task', function() {
  // do whatever debugging you want and stop the loop if needed.
  grunt.task.run(['less']);
});

然后mylesswatch.

更新:

这个想法是,由于对lessnow 的任何重复调用都会通过您的代码 - 如果失败是“期望的”结果并且应该失败,但不是循环,您可以做任何需要提供更具体的输出或防止重复调用的操作。

更新 2:

像这样的东西:

watch: {
    `less`: {
        files: ['**/*.less'],   // or whatever the extension is
        tasks: ['myless']       // your envelope task
    }
}

var flag;

grunt.registerTask('myless', 'My LESS task', function() {
    if(flag === true) {
        // if you are here - it means watch just invoked you repeatedly
        // do whatever you need to analyze the issue (includig running an additional task)

        flag = false;
        return; // you exit task without altering any less files again - 
                // that should NOT trigger watch again
    } else {
        flag = true;
        grunt.task.run(['less']);
    }
});
于 2013-12-16T04:34:43.087 回答