R
R
Russland Russland2017-03-17 08:21:03
Sprites
Russland Russland, 2017-03-17 08:21:03

How to prevent gulp task from executing with empty select?

In general, there is the following task for assembling an svg sprite (symbols)

import gulp from 'gulp';
import svgSymbols from 'gulp-svg-symbols';
import gulpIf from 'gulp-if';
import rename from 'gulp-rename';
import plumber from 'gulp-plumber';
import errorHandler from 'gulp-plumber-error-handler';
import path from 'path';

gulp.task('icons', () => (
  gulp.src('app/icons/**/*.svg')
    .pipe(plumber({errorHandler: errorHandler(`Error in 'icons' task`)}))
    .pipe(svgSymbols({
      templates: [
        path.join(__dirname, '../tasks/icon-templates/svg-symbols.svg'),
        path.join(__dirname, '../tasks/icon-templates/svg-symbols.scss')
      ],
      transformData: (svg, defaultData) => {
        return {
          id: defaultData.id,
          width: svg.width,
          height: svg.height,
          name: svg.name
        };
      }
    }))
    .pipe(gulpIf(/\.scss/, gulp.dest('app/styles/base')))
    .pipe(gulpIf(/\.svg$/, rename('icons.svg')))
    .pipe(gulpIf(/\.svg$/, gulp.dest('dist/assets/img/')))
));

The problem is that this task creates svg and scss files even if there are no icons in the source directory, the output files themselves are empty. What could be the problem? How to stop the execution of a task with an empty thread?

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