X
X
xonar2019-08-10 01:48:50
JavaScript
xonar, 2019-08-10 01:48:50

How to make a assembler with gulp?

Hello. Recently, as I got acquainted with gulp, I can run tasks, but I'm too lazy to do it all the time. How to make a collector so that with one command it completes all the tasks that are available.
For example, scss in css, compressed images that are needed at startup 1 run. Something like npm run build and it would do it all. Here is my code. I would be glad if you show an example and stick the official documentation on the documentation, otherwise I didn’t really understand looking at the documentation.

'use strict';
 
var gulp = require('gulp');
var sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
let cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');

gulp.task('style', function(){
    return gulp.src('source/scss/index.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({browsers: ['last 2 versions'],cascade: false}))
    .pipe(cleanCSS({compatibility: 'ie8'}))
    .pipe(gulp.dest('./build/css'));
})


gulp.task('image', () =>
    gulp.src('source/images/**')
    .pipe(imagemin([
        imagemin.gifsicle({interlaced: true}),
        imagemin.jpegtran({progressive: true}),
        imagemin.optipng({optimizationLevel: 5}),
        imagemin.svgo({
            plugins: [
                {removeViewBox: true},
                {cleanupIDs: false}
            ]
        })
    ]))
    .pipe(gulp.dest('build/img'))
);

gulp.task('watch', function(){
    gulp.watch('/source/scss/*.scss',  gulp.parallel('style'))
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-08-10
@xonar

gulp.task('default', gulp.parallel('style', 'image', 'watch'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question