gulp需要删除文件或者文件夹,有几种方式:
1.使用gulp-shell插件,使用命令行模式,可以带一个切目录命令
var shell = require('gulp-shell')
shell.task([cmd1,cmd2,cmd3...], {cwd: path})
2.使用gulp-clean插件
vargulp=require('gulp'),
clean = require('gulp-clean');//清理文件或文件夹
gulp.task('clean',function(){
gulp.src('dist/',{read:false})
.pipe(clean());
})
3.使用del插件,全路径,可自选其他参数.force参数用于强制删除非当前目录的文件。
var del = require('del');
del([file1,file2...])
del.sync([file1,file2...], { force: true })
返回Promise
返回string[]带有删除路径的路径,同步删除。
参数解析
patterns
类型: string | string[]
options
类型: object
您可以指定任何的globby选项,除了以下选项。与此相反的 globby 默认值,expandDirectories ,onlyFiles ,和followSymbolicLinks 是 false 默认。
force
类型:boolean
默认值:false
允许删除当前工作目录和外部目录。
dryRun
类型:boolean
默认值:false
查看将被删除的内容。