如何使用gulp任务排除包含文件的目录

时间:2015-10-21 10:22:04

标签: gulp

如何使用gulp清除所有目录和文件除自定义脚本目录和此目录中的所有js文件?

  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-bower": "0.0.10",
    "rimraf": "2.2.8",
    "gulp-concat": "2.5.2",
    "gulp-uglify": "1.2.0",
    "gulp-connect": "2.2.0",
    "gulp-clean": "0.3.1"
  } 

此任务会删除custom-scripts文件夹中的文件

gulp.task('clean', function () {
    return gulp.src(['./Scripts/lib', '!./Scripts/lib/custom-scripts', '!./Scripts/lib/custom-scripts/*.js'], { read: false })
         .pipe(clean());
})

1 个答案:

答案 0 :(得分:0)

clean()替换为gulp-rimrafgulp-ignore解决了这个问题。

  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-bower": "0.0.10",
    //"rimraf": "2.2.8",
    "gulp-concat": "2.5.2",
    "gulp-uglify": "1.2.0",
    "gulp-clean": "0.3.1",
    "gulp-ignore": "^2.0.1",
    "gulp-rimraf":  "^0.2.0"
  }



var gulp = require("gulp");
var rimraf = require("gulp-rimraf");
var bower = require('gulp-bower');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ignore = require('gulp-ignore');


gulp.task('clean', function () {
    return gulp.src('./Scripts/lib', { read: false })
        .pipe(ignore('./Scripts/lib/custom-scripts/**'))
        .pipe(rimraf());
});