なんばんせんじだかわかりません
delは対象になるファイルやらディレクトリが存在しないとエラーを吐くから、
fsで事前に存在をチェックするのがいいんだろうなと思いました
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
del = require('del'); | |
gulp.task('clean', function(done) { | |
var files = fs.readdirSync('dist'); | |
var targets = []; | |
if(files.length) { | |
targets.push('dist/*'); | |
} | |
if(fs.existsSync('your-file.js')) { | |
targets.push('your-file.js'); | |
} | |
if(targets.length) { | |
return del(targets); | |
} else { | |
done(); | |
console.log('Delete directory and file not found.'); | |
} | |
}); |
working directory以外のものを消すならば、 delのオプションで force: true
する。
return del(targets, {force: true});