Note task does not perform correctly

Asked

Viewed 26 times

0

const sass = require('gulp-sass')
const gulp = require('gulp')

let caminho = `scss/**/*.scss`

gulp.task('scss', () => {
    return gulp.src(caminho)
        .pipe(sass())
        .pipe(gulp.dest('css'))
})

gulp.task('observa', () => {
    return gulp.watch((caminho, ['scss']))
})

1 answer

1

Note in the line below:

return gulp.watch((caminho, ['scss']))

You are using the comma operator, which takes precedence over separating the arguments from the function since you are using a group of extra parentheses.

According to the documentation, comma operator evaluates all expressions between them, from left to right, and returns the value of the last of them.

So let’s see what you’re passing to the first argument of watch:

const caminho = `scss/**/*.scss`;
console.log((caminho, ['scss']));

Note that, although caminho is being evaluated, only ['scss'] will be returned, since it is the last expression between the commas.

To solve, simply remove the internal parentheses to denote function application syntax, where N arguments are separated by commas:

return gulp.watch(caminho, ['scss']);

Although not the cause of your problem, I also put a semicolon at the end of the lines. It may seem "fresh," but I’ve created this habit to avoid some bizarre situations which may occur if you do not use the semicolon on all lines (see more on the subject here).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.