A
A
Andrey Chernyshev2015-09-23 00:44:28
Node.js
Andrey Chernyshev, 2015-09-23 00:44:28

How to pass callback to gulp task?

The point is. There is a gulp task jade, to which the path of the location of the view files is passed, and then the task will convert each file to html. The problem is that for each file it does a livereload reload and for each file it does a notification.

gulp.task 'jade', ->
  gulp.src paths.views
    .pipe plumber errorHandler: notify.onError "Error: <%= error.message %>"
    .pipe jade
      pretty: true
    .pipe gulp.dest paths.app
    .pipe connect.reload()
    .pipe notify
      message: "jade task complete"
      open: "http://localhost:#{config.port}"

It all looks like this:
2828f126756e47fba02dfffa866312fc.png
upd.
So far I've managed with this solution:
gulp.task 'jade', ['jade-compile'], ->
  gulp
    .src paths.app
    .pipe connect.reload()
    .pipe notify
      message: "jade task complete"
      open: "http://localhost:#{config.port}"

# Сам процесс сборки
gulp.task 'jade-compile', ->
  gulp.src paths.jade.views
    .pipe plumber errorHandler: notify.onError "Error: <%= error.message %>"
    .pipe jade
      pretty: true
    .pipe gulp.dest paths.app

Not the most elegant, but working.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Chashchinov, 2015-09-24
@kudesa

See frontender.info/handling-sync-tasks-with-gulp-js

R
ROBsoer, 2015-09-26
@ROBsoer

Your option is not the worst, you just need to use return

return gulp.src('path')
   .pipe().....

When you want to organize the sequential execution of tasks, this is necessary, otherwise all tasks will start at the same time.
As an option, distribute the files into blocks and compile only the output page where these blocks are assembled. But if there are several pages, then there will also be several messages.
as an example file structure:
jade
├ common/
    ├ header.jade
    └ footer.jade
├ layouts/
     └ layout.jade
├ index.jade
├ page2.jade
└ page3.jade

then path = "jade/*.jade" without subfolders

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question