onlineracoon onlineracoon - 3 months ago 16
Javascript Question

Glob pattern - full directory except sub folders

Basically I'm creating a Gulp task which copies a folder and all it's sub folders, but I want it to skip 2 directories like so:



var gulp = require('gulp');

gulp.task('copy', function () {
return gulp.src(['./src/**', '!./src/scripts/', '!./src/styles/'])
.pipe(gulp.dest('./dist'));
});





But it won't work, it will copy the src directory including the src/scripts and src/styles sub folders.

How could I make it work that it would copy the src directory + sub folders (and sub - sub folders) except the src/scripts and src/styles folders.

Answer

I guess you could do something like

gulp.task('copy', function () {
  return gulp.src([
    './src/**',
    '!./src/{scripts,scripts/**}',
    '!./src/{styles,styles/**}'
  ])
  .pipe(gulp.dest('./dist'))
})

To exclude the scripts and styles folders, including all its contents