Answer the question
In order to leave comments, you need to log in
How to remove only what has been removed?
There are such tricks
gulp.task('imgs', function() {
return gulp.src('src/blocks/**/*.{jpg,jpeg,png,gif,svg}')
.pipe(flatten())
.pipe(gulp.dest('public/imgs'));
});
gulp.task('default', ['imgs'], function() {
gulp.watch('src/blocks/**/*.{jpg,jpeg,png,gif,svg}', ['imgs']);
});
Answer the question
In order to leave comments, you need to log in
don't bother, I think. make a clean task that cleans everything, which is run before building the production build.
But if you feel like it, look at Ilya Kantor's screencast. In one of the parts, he tells how you can do a synchronous deletion of files in dist and src
I agree about the trouble, it's not worth it, but if you really want to, then something like this:
// Gulp 4
gulp.watch( 'src/blocks/**/*.{jpg,jpeg,png,gif,svg}', gulp.series( 'imgs' ) ).on( 'unlink', function( delPath ) {
let path = require( 'path' ), file = path.basename( delPath );
try {
require( 'fs' ).unlinkSync( path.join( 'public', 'imgs', file ) );
} catch (e) { console.log(e); }
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question