我想在我的Gulpfile中运行一些任务,并让它们的输出替换或更改现有文件。例如,我想运行wiredep
并让代码替换index.html
中的块(这是与源相同的文件),所以基本上我有以下内容:
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app/index.html')) // Have wiredep operate on the source
})
但是这会产生一个EEXIST
错误。
同样,我想运行stylus
命令,并将输出管道到一个已经存在的文件(因为它以前运行过)。
我有任何选择,但每次运行del
?似乎Gulp应该能够很容易地覆盖现有的文件,但我不能想出一个简单的方法。
gulp.dest()
期望一个目录。您正在传递一个文件名。
gulp试图创建目录app/index.html
,但它不能,因为已经有一个同名的文件。
您所需要做的就是传递app/
作为目标目录:
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app/'));
})
您应该能够使用gulp.dest
,它有一个选项overwrite
options.overwrite
类型:布尔默认:真
指定是否覆盖具有相同路径的现有文件。
一切都会好的
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app')) // Have wiredep operate on the source
})
Gulp有overwrite
选项
gulp.task('bower', () => {
return gulp.src('input/*.js')
.pipe(gulp.dest('output/',{overwrite:true}))
})
另一个例子const { src, dest } = require('gulp');
function copy() {
return src('input/*.js')
.pipe(dest('output/',{overwrite:true}));
}
完整文档https://gulpjs.com/docs/en/api/dest