0

I installed gulp-changed on my scripts task and it works fine if I pass a string into it (ex: 'output/'). But on my project I'm using a function that returns the dest to be the same as the source:

gulp.task('scripts', function(){
    gulp.src([
            'assets/scripts/**/*.js',
            '!assets/scripts/**/_*.js',
            '!assets/scripts/**/*.min.js'
        ])

        // 1* it works fine with a string
        //.pipe(gulpif(global.isWatching, changed( 'output/' ) ))

        // 2* it doesn't work with the function
        .pipe(gulpif(global.isWatching, changed( function(file) { return file.base; } ) ))

        .pipe(include())
            .on('error', console.log)
        .pipe(babel({
            presets: ['es2015'],
            compact: true
        }))
        .pipe(gulpif(env === "production", uglify().on('error', gutil.log)))
        .pipe(rename({ suffix: '.min' }))

        //.pipe(gulp.dest( 'output/' ));

        //it works if i don't apply changed with a function
        .pipe(gulp.dest( function(file) { return file.base; } ));

});

What am i doing wrong? Maybe I need to change the function. I still want to have the dest the same as the src.

Thanks

sandrina-p
  • 3,794
  • 8
  • 32
  • 60
  • Isn't `file.base` the same for all of your files anyway? `gulp.dest('assets/scripts')` should work and then `changed('assets/scripts')` should as well. – Sven Schoenung Aug 23 '16 at 10:58
  • I have files on `"assets/scripts/folder1"`, `"assets/scripts/folder2"`, etc etc... Still i tried what you said and now it doesn't return nothing att all – sandrina-p Aug 23 '16 at 11:16
  • The reason it doesn't do anything is because you're comparing each source file with itself, so `changed()` never detects any changes. You need to place `rename()` before `changed()`. – Sven Schoenung Aug 23 '16 at 17:41
  • But even that won't solve all your problems. If you change a file that is only included through `include()` the including file with not be updated, because the including file itself hasn't changed. Basically your entire approach of using `gulp-include` in combination with `gulp-changed` is flawed. – Sven Schoenung Aug 23 '16 at 17:48
  • I didn't figured out a way with changed(), then i tried cached and it worked, like here: http://stackoverflow.com/a/31844630/4737729 – sandrina-p Aug 24 '16 at 07:57
  • Have same problem here, anyone has a solution? – Lying_cat Nov 10 '19 at 14:35

0 Answers0