I have a few tasks in my Gulpfile that I would like to run and either have their output replace or alter an existing file. For example, I want to run wiredep
and have code replace the blocks inside index.html
(which is the same file as the source) so basically I have the have the following:
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app/index.html')) // Have wiredep operate on the source
})
But this creates an EEXIST
error.
Similarly, I would like to run the stylus
command, and pipe the output to a file that already exists (because it was previously run).
Do I have any choise but to run del
each time? It seems like Gulp should be able to easily overwrite existing files but I can't figure out a simple way.
gulp.dest()
expects a directory. You're passing it a file name.
What happens is that gulp tries to create the directory app/index.html
, which it can't since there's already a file with that name.
All you need to do is pass app/
as the destination directory:
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app/'));
})
You should be able to use gulp.dest
which has an option overwrite
options.overwrite
Type: BooleanDefault: true
Specify if existing files with the same path should be overwritten or not.
It will be ok.
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app')) // Have wiredep operate on the source
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With