L
L
livesega2016-10-17 16:49:26
Node.js
livesega, 2016-10-17 16:49:26

How to work with stream in Gulp.js?

There is a code:

var gulp = require('gulp'),
ftp = require('gulp-ftp'),
sass = require('gulp-sass');

gulp.task('sass', function() {
  return gulp.src('./src/**/*.scss')
    .pipe(sass({
      outputStyle: 'expanded',
      indentType: 'tab',
      indentWidth: 1,
      sourceComments: false
    }))
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(gulp.dest('./build/'))
    .pipe(gulpif(project.ftp.upload, ftp({
      host: project.ftp.host,
      user: project.ftp.username,
      pass: project.ftp.password,
      remotePath: project.ftp.remotePath
    })))
    .pipe(browserSync.stream());
});

How to move ftp to a separate function? Necessary because this code is repeated in other tasks (html/jade, js/coffeescript, pictures, fonts, etc.), which is not cool.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2016-10-17
@livesega

Transfer the upload to FTP in a separate task. Then chain it with runSequence .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question