F
F
fantazerno2017-08-16 16:03:27
Node.js
fantazerno, 2017-08-16 16:03:27

How to create a rule for Gulp task?

There is a task for assembling SVG

gulp.task('svg', function () {
    var svgSrc = gulp.src(['app/img/svg/**.*','!app/img/svg/defs.svg','!app/img/svg/sprite.svg']);
    svgSrc
        .pipe(svgmin({
            js2svg: {
                pretty: true
            }
        }))
        .pipe(cheerio({
            run: function ($) {
                $('[fill]').removeAttr('fill'); //remove if need color icon
                $('[style]').removeAttr('style');
            },
            parserOptions: {xmlMode: true }
        }))
        .pipe(svgSprite( {
            mode:{
                symbol: true,
            }
        }))
        .pipe(rename("pack.html"))
        .pipe(gulp.dest('app/img/'))
        .pipe(gulp.dest('dist/img/'))

    svgSrc
        .pipe(svgSpriteTempl())
        .pipe(gulp.dest('app/img/'))
        .pipe(gulp.dest('dist/img/'))

    var  svgArray =[];
    fs.writeFile("app/html/block_html/_svg.pug",'');
    fs.readdirSync('app/img/svg').forEach(file => {
      svgArray.push("\'"+file+"\'");
    })
    fs.writeFile("app/html/block_html/_svg.pug",'- svgArray = ['+ svgArray+'];');

});

How to implement this:
If the file name has a prefix to the name.
For example, in the file fileName--color.svg there is " --color ", then this pipe does not run
.pipe(cheerio({
            run: function ($) {
                $('[fill]').removeAttr('fill'); //remove if need color icon
                $('[style]').removeAttr('style');
            },
            parserOptions: {xmlMode: true }
        }))

Thanks in advance for your advice.

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