I use gulp-stylefmt and it run every time I save any CSS file:
function stylelint () {
return gulp.src('src/**/*.css')
.pipe($.stylefmt())
.pipe(gulp.dest('src/'));
}
Same time gulp.watch watches the path src/**/*.css
and run stylelint task again.
Console output:
[16:32:24] Starting 'stylelint'...
[16:32:25] Finished 'stylelint' after 554 ms
[16:32:25] Starting 'stylelint'...
[16:32:25] Finished 'stylelint' after 60 ms
[16:32:25] Starting 'stylelint'...
[16:32:25] Finished 'stylelint' after 33 ms
[16:32:25] Starting 'stylelint'...
[16:32:25] Finished 'stylelint' after 36 ms
[16:32:26] Starting 'stylelint'...
[16:32:26] Finished 'stylelint' after 34 ms
[16:32:26] Starting 'stylelint'...
[16:32:26] Finished 'stylelint' after 29 ms
[16:32:26] Starting 'stylelint'...
[16:32:26] Finished 'stylelint' after 27 ms
[16:32:26] Starting 'stylelint'…
[16:32:26] Finished 'stylelint' after 32 ms
There is a way to correct this behavior and run stylelint task only one time?
UPD. I added gulp-cached and now it runs only twice. Can I improve it to run once?
function stylelint () {
return gulp.src('src/**/*.css')
.pipe($.cached('stylelint'))
.pipe($.stylefmt())
.pipe($.cached('stylelint'))
.pipe(gulp.dest('src/'));
}
I think I repeated the solution 1 by @SvenSchoenung with since and gulp.lastRun. In my case I did it without gulp-cached, but I use gulp4
function stylelint () {
return gulp.src('src/**/*.css', {since: gulp.lastRun(stylelint)})
.pipe($.stylefmt())
.pipe(gulp.dest('src/'));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With