"grunt watch" 总是在发生致命错误后停止监视 - 如何让它在几秒钟后自动重试?

"grunt watch" always stops watching after fatal errors - how to make it retry after some seconds automatically?

在一些项目中,我使用 G运行t 来完成 SASS 编译等任务。基本上它就像一个魅力,但只要我在 SASS 文件中输入,显然有时会发生错误,因为我没有完成。

我的G运行tfile的watch任务是这样的:

// watch files
watch: {
    sass: {
        files: ['web/var/static/**/*.scss','web/var/static/lib/**','web/var/static/js/*.js'],
        tasks: ['default']
    }
},

我在 cli 中使用 grunt watch 启动它。

G运行t 日志中的示例错误:

Completed in 1.968s at Wed Sep 18 2019 13:43:01 GMT+0200 (Central European Summer Time) - Waiting...
>> File "web/var/static/sass/layout/footer.scss" changed.
Running "sass:dist" (sass) task

Running "autoprefixer:dist" (autoprefixer) task
>> 4 autoprefixed stylesheets created.

Running "cssmin:dist" (cssmin) task
>> 4 files created. 706.54 kB → 598.46 kB

Running "concat:dist" (concat) task

Running "uglify:main" (uglify) task

Done.
Completed in 1.769s at Wed Sep 18 2019 13:43:25 GMT+0200 (Central European Summer Time) - Waiting...
>> File "web/var/static/sass/layout/footer.scss" changed.
Running "sass:dist" (sass) task
Fatal error: Error: property "ul" must be followed by a ':'
        on line 52 of web/var/static/sass/layout/footer.scss
        from line 13 of web/var/static/sass/main.scss
>>     ul

   ----^

如果发生这种情况,我总是不得不重新运行任务,因为g运行t 停止观看。这意味着:

这真的很慢。

有没有人遇到过类似的问题?如何让 g运行t 在发生新文件更改后立即自动重试?

spawn 方法 returns 对生成的 child 的引用。当 child 退出时,调用 doneFunction。您可以从下面的函数 重试 出错:

function doneFunction(error, result, code) {
  // If the exit code was non-zero and a fallback wasn't specified, an Error
  // object, otherwise null.
  error
  // The result object is an object with the properties .stdout, .stderr, and
  // .code (exit code).
  result
  // When result is coerced to a string, the value is stdout if the exit code
  // was zero, the fallback if the exit code was non-zero and a fallback was
  // specified, or stderr if the exit code was non-zero and a fallback was
  // not specified.
  String(result)
  // The numeric exit code.
  code
}