T
T
Tatiana2019-07-27 13:47:44
css
Tatiana, 2019-07-27 13:47:44

gulp error. Compiling sass to css. Where is the mistake?

const gulp = require('gulp'),
    sass = require('gulp-sass'),
    cssmin = require('gulp-cssmin'),
    rename = require('gulp-rename'),
    plumber = require('gulp-plumber'),
    watch = require('gulp-watch');

gulp.task('sass', function () {
//указываем за какой папкой следить
  return gulp.src('./sass/**/*.sass')
    .pipe(plumber())
        //указываем куда сохранять CSS
    .pipe(gulp.dest('./css'));
});

gulp.task('cssmin', function () {
//указываем где лежит CSS
  gulp.src('./css/*.css')
    .pipe(plumber())
    .pipe(cssmin())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest('dist'));
});

gulp.task('watch', function(){
  gulp.watch('./sass/**/*.sass', ['sass']);
  gulp.watch('./css/**/*.css', ['cssmin']);
});

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

5d3c2bcbc6f62278191936.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2019-07-27
@tanyafox2

I think the problem is in the watch function. depending on what version of gallp you have.
my watch function is written like this

gulp.task('watch', function() {
  gulp.watch('src/sass/*.scss', gulp.series('sass'));
});

K
Kirill Udaltsov, 2019-07-27
@uashkki

Most likely it's a version issue, here, it seems, this problem was sorted out:
Gulp does not work, gives an error?
Try like this:

const gulp = require('gulp'),
    sass = require('gulp-sass'),
    cssmin = require('gulp-cssmin'),
    rename = require('gulp-rename'),
    plumber = require('gulp-plumber'),
    watch = require('gulp-watch');

gulp.task('sass', function(done) {
    gulp.src("./sass/**/*.sass")
        .pipe(plumber())
        .pipe(sass())
        .pipe(gulp.dest("./css"))
        .pipe(browserSync.stream());


    done();
});

gulp.task('cssmin', function () {
//указываем где лежит CSS
  gulp.src('./css/*.css')
    .pipe(plumber())
    .pipe(cssmin())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest('dist'));
});

gulp.task('watch', function(){
  gulp.watch('./sass/**/*.sass', gulp.series('sass'));
  gulp.watch('./css/**/*.css', gulp.series('cssmin'));
});

gulp.task('default', gulp.series('sass', 'cssmin', 'watch'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question