dlmanning / gulp-sass

SASS plugin for gulp
MIT License
1.56k stars 382 forks source link

Watch imported files #744

Closed albertogiovanelli91 closed 2 years ago

albertogiovanelli91 commented 5 years ago

Can I watch for changes file imported inside my main.sass file?

How can I pass node-sass options like --watch and --recursive inside the task. I tried the following but seems to not work:

gulp.task('sass', function () { return gulp.src(app+'/sass/main.sass') .pipe(sass({watch: true, recursive: true})) .pipe(gulp.dest(public+'/css')); });

Thanks

gabriel-lima96 commented 4 years ago

You should check the 'watch' from gulp api:

https://gulpjs.com/docs/en/api/watch

tiagolobao commented 4 years ago

I had a file called style.scss that calls another 3 includes files in the same folder. I watch for changes in all files, but it compiles only the style.scss file. I could archive this by using the API funcion watch from gulp like this:


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

function scss(){
  // here you put all the files that needs to be compiled
  return gulp.src('resources/style.scss')
    .pipe(sass({outputStyle: 'compressed',includePaths: ['./resources']}).on('error', sass.logError))
    .pipe(gulp.dest(dest));
}

gulp.task('watch', () => {
  // here you put all files that needs to be watched
  gulp.watch('resources/*.scss', { events: 'all' }, function(cb) { 
    scss();
    cb();
  });
});