E
E
Eugene Chefranov2019-08-21 10:47:32
JavaScript
Eugene Chefranov, 2019-08-21 10:47:32

Correct transition of Gulp from version 3 to version 4?

Automatically updated from version 3 to version 4 and, accordingly, tasks stopped running. Can you help rewrite the following three tasks to the new syntax for an example?

gulp.task('default', ['watch']);

gulp.task('watch', function () {
    gulp.watch('src/img/*', ['compress']);
});

gulp.task('css', function () {
    return gulp.src('src/scss/*.scss')
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on('error', sass.logError)
        .pipe(cleanCSS())
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist/css'))
        .pipe(browserSync.stream());
});

There, as I understand it, the series function is now used, does the first task in my example also run through series?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FabiBoom, 2019-08-21
@Chefranov

const gulp = require('gulp');

function compress() {
    // compress task
}

function watch() {
    gulp.watch('src/img/*', compress);
}

function css() {
    return gulp
        .src('src/scss/*.scss')
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(sass())
        .on('error', sass.logError)
        .pipe(cleanCSS())
        .pipe(
            autoprefixer({
                browsers: ['last 2 versions'],
                cascade: false
            })
        )
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist/css'))
        .pipe(browserSync.stream());
}

module.exports.default = gulp.series(watch); // ну если один таск можно и просто `watch`.
module.exports.watch = watch;
module.exports.css = css;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question