我不明白为什么这个简单的脚本会根据del插件的设置而有所不同。
当我启动gulp sass时,我只想清理public/css dir,并从sass“编译”public/css。到目前为止还不错:
gulp.task('clean-css', del.bind(null,['./public/css']));
gulp.task('sass', ['clean-css'], function () {
return gulp.src('./resources/sass/**/*.scss')
.pipe(plugins.sass({outputStyle: 'compressed'}))
.pipe(gulp.dest('./public/css'));
});但是,如果将清洁-css任务更改为:
gulp.task('clean-css', del(['./public/css']));那么它每隔一次就能工作一次。第一次清除并生成css,下一次它删除目录,但不生成任何内容。
那么,del(['./public/css'])和del.bind(null,['./public/css'])有什么区别呢?为什么它会以这种方式影响脚本?
更新:当它没有生成任何我看到的错误时的:
events.js:141
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open 'C:\Users\XXXX\gulp-project\public\css\style.css'
at Error (native)发布于 2015-07-14 08:51:09
tl;博士
如果不提供回调,Gulp不知道何时完成del。无论是否使用bind,如果您的sass任务在del之前运行,并且要删除的文件实际上存在,则del每隔一次工作一次。
根据吞咽文件,您还应该向del提供回调方法。当任务完成时,这是古普怎么知道:
var gulp = require('gulp');
var del = require('del');
gulp.task('clean:mobile', function (cb) {
del([
'dist/report.csv',
// here we use a globbing pattern to match everything inside the `mobile` folder
'dist/mobile/**/*',
// we don't want to clean this file though so we negate the pattern
'!dist/mobile/deploy.json'
], cb);
});
gulp.task('default', ['clean:mobile']);我认为每次运行任务的顺序是不同的,因为gulp不知道在不提供回调时何时完成del。根据文档
如果要创建任务按特定顺序运行的系列,则需要执行两项工作:
https://stackoverflow.com/questions/31400418
复制相似问题