F
F
Finesse2015-08-16 06:51:41
gulp.js
Finesse, 2015-08-16 06:51:41

How to insert a file opening in the middle of a stream?

For example, there is gulpfile.js with the following content:

var gulp = require('gulp');
var svg2png = require('gulp-svg2png');
var spritesmith = require('gulp.spritesmith');

gulp.task('svg2png', function() {
  // Модуль gulp.spritesmith не умеет читать содержимое файлов из потока, поэтому изображения сохраняются во временную директорию ./images/tmp
  return gulp.src('./images/sprite/*.{svg}')
    .pipe(svg2png())
    .pipe(gulp.dest('./images/tmp/'));
});

gulp.task('default', ['svg2png'], function() {
  var data = gulp.src('./images/tmp/*.{png}')
    .pipe(spritesmith({
      imgName: 'sprite.png',
      cssName: 'sprite.css'
    }));
  data.img.pipe(gulp.dest('./images/'));
  data.css.pipe(gulp.dest('./css/'));
});

The build is started with the command gulp default. How to implement all this procedure in one task (task)? Intuitively comes the idea to combine 2 streams:
var gulp = require('gulp');
var svg2png = require('gulp-svg2png');
var spritesmith = require('gulp.spritesmith');

gulp.task('default', function() {
  var data = gulp.src('./images/sprite/*.{svg}')
    .pipe(svg2png())
    .pipe(gulp.dest('./images/tmp/'))
    .pipe(gulp.src('./images/tmp/*.{png}'))
    .pipe(spritesmith({
      imgName: 'sprite.png',
      cssName: 'sprite.css'
    }));
  data.img.pipe(gulp.dest('./images/'));
  data.css.pipe(gulp.dest('./css/'));
});

But it doesn't work because the thread is interrupted by .pipe(gulp.src('./images/tmp/*.{png}')). Is it possible somehow to open a file inside a thread without creating new jobs?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question