Watches for SASS files modifications thanks to gulp-watch
, while adding @import
ing SASS files to the stream thanks to gulp-fn
.
npm install --save-dev gulp-watch-sass
const gulp = require("gulp")
const sass = require("gulp-sass")
const watchSass = require("gulp-watch-sass")
gulp.task("sass:watch", () => watchSass([
"./public/**/*.{scss,css}",
"!./public/libs/**/*"
])
.pipe(sass())
.pipe(gulp.dest("./public")));
Creates a watcher that will spy on files that are matched by glob
which can be a glob string or array of glob strings. On file change, the modified file and the @import
ing files will be added to the stream.
You can watch for CSS files modifications in addition to SASS ones. In this case, if the modified file is a CSS file, then only the @import
ing files will be added to the stream.
This object is passed to the gulp-watch
options directly.
Mimics node-sass' includePaths
option.
gulp.task("sass", () => gulp.src([
"./public/**/*.scss",
"!./public/libs/**/*"
])
.pipe(sass())
.pipe(gulp.dest("./public")));
gulp.task("sass:watch", () => {
gulp.watch([
"./public/**/*.scss",
"!./public/libs/**/*"
], ["sass"]);
});
This works well, but each time a SASS file is updated, all the project's SASS files are recompiled, which can be quite long when working on big projects.
gulp-watch
doesn't take @import
ing files into account:
gulp.task("sass:watch", () => watch([
"./public/**/*.scss",
"!./public/libs/**/*"
])
.pipe(sass())
.pipe(gulp.dest("./public")));
This recompiles only modified SASS files, but because @import
statements are not resolved, the stylesheets may not be refreshed as expected.