question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watch/recompile only changed sass/scss files

See original GitHub issue

Hi, This question might be already answered, but i couldn’t find the answer. Recently I switch from Compass SASS to Gulp-sass. So, is it possible with the Watcher to recompile only changed SCSS files? I have huge amount of SCSS files (~60) so it takes around 7-8sec every time I change ONE file. Here is my task and watcher

sassSources = ['../sass/**/*.scss'];

gulp.task('sass', function() {
    return gulp.src(sassSources)
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(autoprefixer())
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('resources/css'));
});

gulp.task('watch', function() {
    gulp.watch(sassSources, ['sass'])
    .on('change', function(event) {
        console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    });
});

Any help is appreciated !

Thanks !

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
venelinncommented, Mar 10, 2016

I found a solution. You need to install the following: gulp-sass-grapher path gulp-watch

And this is the working task:

gulp.task('watch-sass', function() {
    var loadPaths = path.resolve('../sass/');
    sassGrapher.init('../sass/', { loadPaths: loadPaths });
    return watch('../sass/**/*.scss', { base: path.resolve('../sass/') })
      .pipe(sassGrapher.ancestors())
      .pipe(sass({
        includePath: loadPaths
      }))
      .pipe(autoprefixer(autoprefix))
      .pipe(gulp.dest('./resources/css'));
  });

Good luck !

1reaction
yoiangcommented, Mar 10, 2016

Haha wow, that’ll do it too, thanks 😃

It would be nice to have this as a gulp-sass one-step option!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp sass compile only changed changed files' folder
In our pre-production server, we have a bash that run and compiles all siblings scss files when you save one. But i'm failing...
Read more >
Upgrade SASS / SCSS to Use Latest CSS - YouTube
In VSCode we use extension that watches SCSS file and converts SCSS ... SASS Compiler may not do anything if you use this...
Read more >
How to compile SASS into CSS and watch for changes?
Watching for changes in SASS. Just add a --watch flag in the command to watch the changes made to the Sass file in...
Read more >
Sass, SCSS, and Less | CLion Documentation - JetBrains
To compile your code automatically, you need to configure a Sass, Less, or SCSS File Watcher which will track changes to your files...
Read more >
Dart Sass Command-Line Interface
It can also compile all Sass files in a directory to CSS files with the same ... Sass will only compile stylesheets whose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found