node.js - Only compile sass if a file has changed using gulp -
i'm trying rebuild gulp file bit more efficient, , i'm having trouble getting styles
task compile if file has changed.
i found this question, answer doesn't seem working me.
let's have repo organized so:
/dev /assets /styles all.css /src /assets /styles all.scss _header.scss gulpfile.js package.json
i want overwrite all.css
if change has been made in either of sass files. so, if save _header.scss
no changes had been made, , ran styles
task, should realize code hasn't changed , not overwrite all.css
.
i looking @ gulp-cached, per question linked above, doesn't seem working me. here's task @ it's basic:
var gulp = require("gulp"), cached = require("gulp-cached"), sass = require("gulp-sass"); gulp.task("styles", function() { return gulp.src(src + "/assets/styles/all.scss") .pipe(sass().on("error", sass.logerror)) .pipe(cached("sass_compile")) // should skip dest if cache same .pipe(gulp.dest(dev + "/assets/styles")); });
the cached
pipe doesn't seem working in instance. run gulp styles
, still overwrites all.css, if no changes have been made, if didn't re-save file.
the more complex task i'd use is:
var gulp = require("gulp"), cached = require("gulp-cached"), sourcemaps = require("gulp-sourcemaps"), sass = require("gulp-sass"), autoprefixer = require("gulp-autoprefixer"), // set environment paths src = "./src", dev = "./dev", dist = "./dist"; gulp.task("styles", function() { return gulp.src(src + "/assets/styles/all.scss") .pipe(sourcemaps.init()) .pipe(sass().on("error", sass.logerror)) .pipe(autoprefixer("last 2 version", "ie 8", "ie 9")) .pipe(sourcemaps.write()) .pipe(cached("sass_compile")) // should skip dest if cache same .pipe(gulp.dest(dev + "/assets/styles")); });
would appreciate guidance on this. much.
edit 1: note all.scss
in demo contains @import "_header";
.
edit 2: okay, figured out gulp-cached
seems working fine in watch
task. revised question: how can same type of functionality outside of watch task?
try gulp-changed instead. believe works on last modified date of file, sounds want.
Comments
Post a Comment