D
D
drtvader2015-12-04 17:10:24
Node.js
drtvader, 2015-12-04 17:10:24

Why is Gulp watch constantly processing files?

Good day to all! Does gulp watch keep updating files on startup? After all, he should only update and shut up when saving the file?

var gulp   = require('gulp'),
    watch  = require('gulp-watch')
    config = require('../../config');

/*
 * Смотрим за изменениями
 */

gulp.task('watch', function(){
    watch([config.watch.html], function(event, cb) {
        gulp.start('html');
    });
    watch([config.watch.less], function(event, cb) {
        gulp.start('less');
    });
    watch(config.watch.jsInternal, function(event, cb) {
        gulp.start('js-internal');
    });
    watch([config.watch.jsExternal], function(event, cb) {
        gulp.start('js-external');
    });
    watch([config.watch.images], function(event, cb) {
        gulp.start('images');
    });
    watch([config.watch.sprites], function(event, cb) {
        gulp.start('sprites');
    });
    watch([config.watch.fonts], function(event, cb) {
        gulp.start('fonts');
    });
});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Kravchenko, 2015-12-04
@mydearfriend

I will assume that you save the files in the same place from where you take

var src = '*/**';
gulp.src(src)
  .pipe(somePlugin)
  .pipe(gulp.dest(src));

post gulpfile.js code

A
Arthur Gurinovich, 2015-12-04
@ArthurGurinovich

But could you publish the task itself in order to more accurately determine the cause?

S
Sergey, 2015-12-05
@Sergamers

Show the work of your tasks, what are you calling ('html', 'less', etc.) The jamb lies there.
Example of a work task + watch

gulp.task('default', ['run-beats']);

gulp.task('run-beats', () => {
  gulp.start('clean-css');
  gulp.start('beats-watch-sass');
});

gulp.task('clean-css', () => {
  console.log('Чистим папку app/css/*');
  del(['app/css/**', '!app/css']);
});

gulp.task('beats-sass',  () => {
  console.log('Работы с css файлами в app/css/*');

  return gulp.src('./beats/styles/**/*.scss')           // Какие файлы выбрать
      .pipe(plumber({                                   // обработка ошибок
        errorHandler:  (error) => {
          console.log('Error: ' + error.message);
          this.emit('end');
        }
      }))
      .pipe(sass())                                     // Перевод файлов в sass
      .pipe(autoprefixer({                              // автопрефикс
        browsers: ['> 1%', 'last 10 versions', 'Firefox 5', 'Opera 12', 'ie 8', 'ie 9', 'ie 7']
      }))
      .pipe(gulp.dest('./app/css'))                     // Куда файлы вставить
});

gulp.task('beats-watch-sass', () => {
  console.log('Запускаем отслеживание изменений sass файлов ...');
  gulp.watch('./beats/styles/**/*.scss')
    .on('all', function (event, path) {
      if(event == 'unlink'){
        gulp.start('clean-css');
      }

      gulp.start('beats-sass');
    })
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question