V
V
Vladislav2015-06-19 17:29:30
gulp.js
Vladislav, 2015-06-19 17:29:30

Why in gulp the task launched through watch is not executed correctly?

gulp.task('header', function () {

  gulp.src('../sources/js/progress.js')
  .pipe(minifyJs())
  .pipe(insert.wrap('{literal}', '{/literal}'))
  .pipe(rename('progress_min.js'))
  .pipe(gulp.dest('../_js'));
});

gulp.task('header_watch', function () {
  gulp.watch('../sources/js/progress.js', ['header']);
});

There are two tasks header and header_watch. Header is executed once on startup of gulp header, header_watch (gulp header_watch) waits for changes in the file and if there are any, it starts the first task. The problem is this, if you just run the header, then everything works fine, the necessary js file is created. Running header_watch creates an empty .js file, although header_watch runs the header task, which in turn works fine. What am I doing wrong?
UPDATE:
Now the problem is, when I run the 'topic_thesaurus_new_less' task, everything works fine.
When I run topic_thesaurus_new_watch, everything works and all less files are compiled except for the file in which changes have been made at the moment, i.e. for example, I changed the dropdown.less file and all files are processed normally, except for it.
gulp.task('topic_thesaurus_new_less', function () {
  var fileName = 'topic_thesaurus_new';

  var lessSources = [
    '../sources/less/vendor/*.less',
    '../sources/less/main.less',
    '../sources/less/fonts.less',
    '../sources/less/blocks/collapse.less',
    '../sources/less/blocks/tooltip.less',
    '../sources/less/blocks/range.less',
    '../sources/less/blocks/dropdown.less',
    '../sources/less/blocks/progress.less',
    '../sources/less/blocks/vote.less',
    '../sources/less/blocks/settings.less',
    '../sources/less/blocks/scroll_pagination.less',
    '../sources/less/blocks/suggest.less',
    '../sources/less/blocks/mixins.less',
  ];

  return gulp.src(lessSources)
  .pipe(concat(fileName + '.less'))
  .pipe(less())
  .pipe(base64())
  .pipe(minifyCss())
  .pipe(gzip())
  .pipe(gulp.dest('../_css'));
});

gulp.task('topic_thesaurus_new_watch', function () {
  var lessSources = [
    '../sources/less/vendor/*.less',
    '../sources/less/*.less',
    '../sources/less/blocks/*.less'
  ];

  gulp.watch(lessSources, ['topic_thesaurus_new_less']);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Zachinalov, 2015-06-19
@MrBikus

Correct "header" in the task
and change all ../ in paths to ./

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question