javascript - gulp - how to pipe tasks -
i have 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 want execute tasks 1 after (create sprite -> copy new destination -> delete src).
currently tasks running async, , if try pipe(gulp.src(...)
getting following error: unhandled stream error in pipe
pretty defined in doc : https://github.com/gulpjs/gulp/blob/master/docs/api.md
note: default, tasks run maximum concurrency -- e.g. launches tasks @ once , waits nothing. if want create series tasks run in particular order, need 2 things:
give hint tell when task done, , give hint task depends on completion of another. these examples, let's presume have 2 tasks, "one" , "two" want run in order:
in task "one" add hint tell when task done. either take in callback , call when you're done or return promise or stream engine should wait resolve or end respectively.
in task "two" add hint telling engine depends on completion of first task.
so example this:
var gulp = require('gulp'); // takes in callback engine knows when it'll done gulp.task('one', function(cb) { // stuff -- async or otherwise cb(err); // if err not null , not undefined, run stop, , note failed }); // identifies dependent task must complete before 1 begins gulp.task('two', ['one'], function() { // task 'one' done }); gulp.task('default', ['one', 'two']);
Comments
Post a Comment