I have this task:
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var svgSprite = require("gulp-svg-sprites");
var clean = require('gulp-clean');
gulp.task('sprite-make', function () {
//first task
gulp.src([path.join(conf.paths.src, '/assets/svg/*.svg'), '!' + path.join(conf.paths.src, '/assets/svg/sprite.svg')])
.pipe(svgSprite({
preview: false,
svgPath: path.join(conf.paths.src, '/assets/svg/sprite.svg'),
cssFile: ('_sprite.scss')
}))
.pipe(gulp.dest(path.join(conf.paths.src, '/app/styles')));
//second task
gulp.src(path.join(conf.paths.src, '/app/styles/svg/**/*'))
.pipe(gulp.dest(path.join(conf.paths.src, '/assets/svg')));
//third task
gulp.src(path.join(conf.paths.src, '/app/styles/svg'), {read: false})
.pipe(clean());
});
What I want is to execute this tasks one after another (create the sprite -> copy it to new destination -> delete the src).
Currently the tasks running async, and if I try to do pipe(gulp.src(...)
I am getting the following error: Unhandled stream error in pipe
Pretty well defined in the doc : https://github.com/gulpjs/gulp/blob/master/docs/API.md
Note: By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. If you want to create a series where tasks run in a particular order, you need to do two things:
give it a hint to tell it when the task is done, and give it a hint that a task depends on completion of another. For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:
In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're done or return a promise or stream that the engine should wait to resolve or end respectively.
In task "two" you add a hint telling the engine that it depends on completion of the first task.
So this example would look like this:
var gulp = require('gulp');
// takes in a callback so the engine knows when it'll be done
gulp.task('one', function(cb) {
// do stuff -- async or otherwise
cb(err); // if err is not null and not undefined, the run will stop, and note that it failed
});
// identifies a dependent task must be complete before this one begins
gulp.task('two', ['one'], function() {
// task 'one' is done now
});
gulp.task('default', ['one', 'two']);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments