How do I make gulp delete deleted files while viewing a specific orb template?

I have a task to watch gulp on the globe, looking for changes and updating the output folder. It successfully updates modified files, adds new files, but does not remove deleted files.

The callback looks like this:

var cb = function (event) {
  console.log('Moving assets...');    
  return gulp.src('app/assets/**/*', {base: 'app'})
    .pipe(changed('build/assets'))
    .pipe(gulp.dest('build'));
};

      

The gulp task looks like this:

gulp.watch('app/assets/**/*', cb);

I know the gulp watch is working fine because the callback receives all remote events. But the callback itself cannot remove the remote file from the folder build/assets/

.

Do I have to explicitly handle the remote event or am I missing something?

+3


source to share


1 answer


The question is old, but I think it still matters.

Here is the solution I came across based on ondaplana's answer in this github issue and the documentation of the gulp modules that are used:

Basically, it uses gulp-watch instead of gulp's own clock function to include gulp-filter and modules.



var filter = require('gulp-filter');
var vinylPaths = require('vinyl-paths');
var del = require('del');
var watch = require('gulp-watch');

    var notDeletedFilter = filter(
        function(file) {
            return file.event !== 'unlink' && file.event !== 'unlinkDir';
        },
        {restore: true}
    );

    notDeletedFilter.restore
        .pipe(gulp.dest('dist'))
        .pipe(vinylPaths(del));

    //use gulp-watch instead of gulp native watch function
    watch(['app/assets/**/*'], {events: ['add', 'change', 'unlink', 'unlinkDir']})
        .pipe(notDeletedFilter)
        .pipe(anyModule())
        .pipe(gulp.dest('build'));

      

Documentation:

Gulp recipes

+1


source







All Articles