Problem in task execution with Gulp & SASS?

1

I'm creating a task that compiles, renames, and simplifies files .scss to .css . My file structure looks like this:

assets/
|__ css/
|__ sass/
|   |__ uma-pasta/
|   |   |__ alguns.scss
|   |   |__ arquivos.scss
|   |   |__ vão.scss
|   |   |__ aqui.scss
|   |__ outra-pasta/
|       |__ alguns.scss
|       |__ outros.scss
|       |__ arquivos.scss
|       |__ vão.scss
|       |__ aqui.scss
|__ _variables.scss

But when I run the following task:

gulp.task('sass', function() {
    gulp.src(['!assets/sass/outra-pasta/**/*.scss', 'assets/sass/**/*.scss'])
        .pipe(sass().on('error', sass.logError))
        .pipe(rename({ suffix: '.min' }))
        .pipe(minify())
        .pipe(gulp.dest(PATH + 'assets/css'))
});

The variables located in assets/sass/_variables.scss are not concatenated with the other files, and then I get the following error:

Error in plugin 'sass'
Message:
    assets/sass/uma-pasta/arquivos.scss
Error: Undefined variable: "$variable".
    on line 3 of stdin
>>  width: $variable;
--------^

And the file assets/sass/_variables.scss looks like this:

$variable: 20px;
    
asked by anonymous 15.01.2016 / 19:25

1 answer

1

I confess that I have never used gulp , but if the logic is the same as grunt , I believe you should start by inserting the variable file before inserting the other files. Try the following:

gulp.src([
    'assets/sass/variables.scss', 
    'assets/sass/**/*.scss'
])

If you have other files still in the root folder, just use something like this:

gulp.src([
    'assets/sass/variables.scss', 
    'assets/sass/*.scss', 
    'assets/sass/**/*.scss'
])

So the variables will exist for all files.

Edited:

Another observation, I do not know if it was your mistake to pass the question to the OS or if it really is the error. But the log says it did not find the variable $minhavariavel and the name you gave it was: $variable . Make sure there is no syntax error with the variable names.

    
15.01.2016 / 20:42