How to compile only changed files?
See original GitHub issueI need to compile project with some separate css: public.sass, landing.sass and etc. Task ‘sass-agentcar’ compiled 1.85 sec, task ‘watch’ that watched “gulp.src(‘./sass/*/.{scss,sass}’)” compiled 4+ sec and recompiled all files in /sass directory. How to prettify code? How to compile only changed files?
var gulp = require('gulp'),
$ = require('gulp-load-plugins')();
gulp.task('sass-agentcar', function () {
return gulp.src(['./sass/agentcar.sass', './sass/agentcar/*.sass'])
.pipe($.sourcemaps.init())
.pipe($.sass({
indentedSyntax: true,
errLogToConsole: true,
outputStyle: 'compressed',
}))
// .pipe($.autoprefixer('last 3 version'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
gulp.task('sass-public', function () {
return gulp.src(['./sass/public.sass', './sass/public/*.sass'])
.pipe($.sourcemaps.init())
.pipe($.sass({
indentedSyntax: true,
errLogToConsole: true,
outputStyle: 'compressed'
}))
.pipe($.autoprefixer('last 3 version'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
gulp.task('sass-print', function () {
return gulp.src(['./sass/print.sass', './sass/print/*.sass'])
.pipe($.sourcemaps.init())
.pipe($.sass({
indentedSyntax: true,
errLogToConsole: true,
outputStyle: 'compressed'
}))
.pipe($.autoprefixer('last 3 version'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
gulp.task('sass-landing', function () {
return gulp.src(['./sass/landing.sass', './sass/landing/*.sass'])
.pipe($.sourcemaps.init())
.pipe($.sass({
indentedSyntax: true,
errLogToConsole: true,
outputStyle: 'compressed'
}))
.pipe($.autoprefixer('last 3 version'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
gulp.task('scss-bootstrap', function () {
return gulp.src(['./sass/bootstrap.scss'])
.pipe($.sourcemaps.init())
.pipe($.sass({
errLogToConsole: true,
outputStyle: 'compressed'
}))
.pipe($.autoprefixer('last 3 version'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
gulp.task('watch', function () {
gulp.watch(['./sass/agentcar.sass', './sass/agentcar/*.sass'], ['sass-agentcar']);
gulp.watch(['./sass/public.sass', './sass/public/*.sass'], ['sass-public']);
gulp.watch(['./sass/print.sass', './sass/print/*.sass'], ['sass-print']);
gulp.watch(['./sass/landing.sass', './sass/landing/*.sass'], ['sass-landing']);
gulp.watch(['./sass/bootstrap.scss'], ['scss-bootstrap']);
});
gulp.task('sass', ['sass-agentcar', 'sass-public', 'sass-print', 'sass-landing', 'scss-bootstrap'])
gulp.task('default', ['sass', 'watch']);
Issue Analytics
- State:
- Created 9 years ago
- Comments:8
Top Results From Across the Web
How do I make Makefile to recompile only changed files?
I have been struggling a bit to get make to compile only the files that have been edited. However I didn't have much...
Read more >how to build with make so that only the changed files get build
First, you have to remove the clean dependency from your JYOTI target. Otherwise, everything is always built from scratch.
Read more >How to rebuild only changed files?
I do small change in main.cpp and do run/build. CLion call cmake to rebuild all. Note: cmake alone can rebuild only changed files...
Read more >Avoiding Compilation (GNU make)
Use the command ' make ' to recompile the source files that really need recompilation, ensuring that the object files are up-to-date before...
Read more >compiling only the changed files in the project - Keil forum
Press the 'Build Target' button instead of the 'Rebuild all Target files' button. Note that using the SRC directive forces files to be ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try gulp-watch
https://github.com/gulpjs/gulp/blob/master/docs/recipes/rebuild-only-files-that-change.md
Also you should be able to have 1 gulp sass task for this now, with gulp-watch.
Since you have non-partial files, they should compile into individual files on their own and there’s no need to have a task for each one.
Just be sure your partials that are referenced (
@import
) in the main file have the correct path.It turned out that only the modified file was compiled!
The output is: file.scss - file.css - file.min.css - file.min.css.map
It did not work either to beat Watcher, that he would immediately create the file after the “oneSassFileCompile” function was launched, the files were created only after the Watcher stop.
Exit the situation - launch the assistant task. But again did not find how to transfer parameters. I had to resort to an external variable, I hope it does not work out that many files changed immediately and this variable did not manage to skip all the files.
Sorry for my english. And for my script too, the first time I write to NodeJS and the first time I ran into Gulp!
If it turns out to throw a parameter directly into the subtask, or even better to force the files to be created immediately when the function is called in Watcher, I will be very glad to see the solution!
tags: gulp sass watch only one file change and compile css autoprefixer minify and map
gulpfile.js code: