1

i have problem, when i run gulp watch -> run task styles:build, and all of my less files was recompile. How i can compile only changed file?

gulp.task('styles:build', function () {
    return gulp.src(pathes.src.styles)
        .pipe(changed(pathes.build.styles), {extension: '.css'})
        .pipe(print(function(filepath) {
            return "➔ file was changed: " + filepath;
        }))
        .pipe(plumber())
        .pipe(less({
            plugins: [autoprefix, cleanCSSPlugin],
            paths: ['./', 'web/styles']
        }))
        .pipe(gulp.dest(pathes.build.styles))
});


gulp.task('watch', function() {
   gulp.watch(pathes.src.styles, ['styles:build'])
});

enter image description here

Dmytro Lishtvan
  • 788
  • 7
  • 12
  • Does it run through all the files each time you make a change to a less file or only the first time,when 'watch' task is first run? I believe it is expected behavior that the first time all the files will pass through gulp-changed. – Mark Aug 09 '17 at 20:16
  • @Mark any changes start compile all files, for example i add '; or &nbsp, any changes' and than run full task styles:build – Dmytro Lishtvan Aug 09 '17 at 20:19
  • You need another close paren ) at the end of the changed pipe. – Mark Aug 09 '17 at 20:36
  • @Mark can you write example? – Dmytro Lishtvan Aug 09 '17 at 20:37
  • .pipe(changed(pathes.build.styles), {extension: '.css'})) <-- note I have added another close parenthesis at the end. Try that change and see if it helps although I would think you be getting errors without it. – Mark Aug 09 '17 at 20:39
  • @mark With brackets all okay – Dmytro Lishtvan Aug 09 '17 at 20:45
  • If that fixed it for you, I'll put it into an answer. – Mark Aug 09 '17 at 20:46
  • @mark - i mean -all okay with bracket) There are no superfluous brackets, everything is open and closed – Dmytro Lishtvan Aug 09 '17 at 20:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/151540/discussion-between-mark-and-dmitriy-lishtvan). – Mark Aug 09 '17 at 20:49

2 Answers2

1

You need to modify the line below to add a closing parenthsis:

.pipe(changed(pathes.build.styles, {extension: '.css'}))

Also as I cautioned the first time the task is run it probably will pass through all files.

Mark
  • 143,421
  • 24
  • 428
  • 436
0

i think i found solution just install lessChanged = require('gulp-less-changed') and include him before less pipe

.pipe(lessChanged())
.pipe(less())
Dmytro Lishtvan
  • 788
  • 7
  • 12