Prevent errors from breaking / crashing gulp watch

后端 未结 8 884
我在风中等你
我在风中等你 2020-12-12 09:17

I\'m running gulp 3.6.2 and have the following task that was set up from a sample online

gulp.task(\'watch\', [\'default\'], function () {
  gulp.watch([
            


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 09:56

    A simple solution to this is to put gulp watch in an infinite loop within a Bash (or sh) shell.

    while true; do gulp; gulp watch; sleep 1; done

    Keep the output of this command in a visible area on your screen as you edit your JavaScript. When your edits result in an error, Gulp will crash, print its stack trace, wait for a second, and resume watching your source files. You can then correct the syntax error, and Gulp will indicate whether or not the edit was a success by either printing out it's normal output, or crashing (then resuming) again.

    This will work in a Linux or Mac terminal. If you are using Windows, use Cygwin or Ubuntu Bash (Windows 10).

提交回复
热议问题