【发布时间】:2014-06-24 21:29:47
【问题描述】:
gulp page 上有如下示例:
gulp.task('clean', function(cb) {
// You can use multiple globbing patterns as you would with `gulp.src`
del(['build'], cb);
});
gulp.task('scripts', ['clean'], function() {
// Minify and copy all JavaScript (except vendor scripts)
return gulp.src(paths.scripts)
.pipe(coffee())
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(gulp.dest('build/js'));
});
// Copy all static images
gulp.task('images', ['clean'], function() {
return gulp.src(paths.images)
// Pass in options to the task
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest('build/img'));
});
// the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.images, ['images']);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'scripts', 'images']);
这很好用。但是watch 任务存在一个大问题。如果我更改图像,监视任务会检测到它并运行images 任务。这对clean 任务也有依赖关系(gulp.task('images', **['clean']**, function() {),所以它也会运行。但是我的脚本文件丢失了,因为scripts 任务没有再次启动,clean 任务删除了所有文件。
如何在第一次启动时运行 clean 任务并保留依赖项?
【问题讨论】:
-
出于这个原因,我们最终在 gulp 之外执行了
clean。我认为的串行关系和实际的依赖之间没有区别。 -
@Mathletics 你用什么在 gulp 之外清理它?
-
@AlanH
rm -rf无论你的输出目录是什么
标签: javascript gulp