为了账号安全,请及时绑定邮箱和手机立即绑定

“grunt watch”总是在致命错误后停止观看 - 如何让它在几秒钟后自动重试?

“grunt watch”总是在致命错误后停止观看 - 如何让它在几秒钟后自动重试?

跃然一笑 2021-10-21 13:36:47
在某些项目中,我将 Grunt 用于 SASS 编译等任务。基本上它就像一个魅力,但只要我在 SASS 文件中输入,显然有时会发生错误,因为我没有完成。我的 Gruntfile 的 watch 任务是这样的:// watch fileswatch: {    sass: {        files: ['web/var/static/**/*.scss','web/var/static/lib/**','web/var/static/js/*.js'],        tasks: ['default']    }},我从grunt watchcli 开始。Grunt 日志中的示例错误: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) taskRunning "autoprefixer:dist" (autoprefixer) task>> 4 autoprefixed stylesheets created.Running "cssmin:dist" (cssmin) task>> 4 files created. 706.54 kB → 598.46 kBRunning "concat:dist" (concat) taskRunning "uglify:main" (uglify) taskDone.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) taskFatal 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   ----^如果发生这种情况,我总是必须重新运行任务,因为grunt 停止观看。这意味着:打开控制台窗口停止当前任务重新开始任务更改文件这真的是在放缓。有没有人遇到过类似的问题?发生新文件更改后,如何在出错后自动重试 grunt?
查看完整描述

1 回答

?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

该spawn方法返回对生成的孩子的引用。当孩子退出时,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

}


查看完整回答
反对 回复 2021-10-21
  • 1 回答
  • 0 关注
  • 176 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信