2

In my website build-process, I use gulp-changed to prevent doing all task if unnecessary. However, sometimes it has different behaviours even if declarations are similar.

Does anyone know what I am doing wrong?

case 1 : building htlm / php using partials. works fine! the task process only the first time, if I run it twice in a row

gulp.task('pages', function () {

    var toBuild = src + config.pages.src_pages; // many php/html files
    var partials = src + config.pages.src_partials; // "to be included"
    var DEST = target;

    return gulp.src([toBuild, "!" + partials])
        .pipe(changed(DEST))
        .pipe(fileinclude({  prefix: '@@', basepath: '@file' }))
        .pipe(size())
        .pipe(gulp.dest(DEST));
});

case 2 : building a SVG sprite from multiple svg files. doesn't work! the task runs again if I run it twice in a row

gulp.task('vector', function () {

   var DEST = target + config.assets.images.vector_dest; 
   var configsvg = { // ... config stuff // };

   return gulp.src(src + config.assets.images.vector_src)
        .pipe(changed(DEST))
        .pipe(svgo())
        .pipe(svgSprite(configsvg)).on('error', function (error) {
            console.log(error);
        })
        .pipe(size())
        .pipe(gulp.dest(DEST));
});
Bertrand Engogram
  • 539
  • 1
  • 5
  • 13

2 Answers2

0

The solution is to use gulp-newer module in case of "many to one" file compilation (concatenation etc...)

Thank you to Lim H. gulp-newer vs gulp-changed

Community
  • 1
  • 1
Bertrand Engogram
  • 539
  • 1
  • 5
  • 13
0

May I also suggest gulp-newy in which you can manipulate the path and filename in your own function. Then, just use the function as the callback to the newy(). This gives you complete control of the files you would like to compare.

This will allow 1:1 or many to 1 compares.

newy(function(projectDir, srcFile, absSrcFile) {
  // do whatever you want to here. 
  // construct your absolute path, change filename suffix, etc. 
  // then return /foo/bar/filename.suffix as the file to compare against
}

enter image description here

dman
  • 10,406
  • 18
  • 102
  • 201