Gulp.js, watch task runs twice when saving files

后端 未结 12 1183
花落未央
花落未央 2020-12-15 11:03

Given the following piece of code from my gulpfile.js, everytime I save or change a file, the task runs twice instead of one single time, why is that? I just want it to run

12条回答
  •  既然无缘
    2020-12-15 11:54

    The problem is occurring because your editor, in this case Coda 2, is modifying the file twice on save. The same problem occurs in vim because of how vim creates buffer backups on save.

    The solution to the problem in vim is to add

    set nowritebackup
    

    to your ~/.vimrc file. This changes the default save protocol to only make one edit to the original file.

    In other words, the default save protocol is as follows:

    1. Write the buffer to the backup file
    2. Delete the original file
    3. Rename the backup to the name of the original file

    And adding set nowritebackup simply replaces the original file on save. This protocol exists to reduce risk of data loss in the event of an I/O error on save.

提交回复
热议问题