javascriptgulpgulp-less

Gulp gulp-less to include component sub-folders


My less folders contain sub folders (with more on the way). It looks like so...

Assets
  |- js
  |- less
       |- students
            |- students.less  // ignores
       |- courses
            |- courses.less   // ignores
       |- teachers 
            |- teachers.less  // ignores
       main.less  // gets successfully

Right now my gulpfile.js can find main.less just fine. But how can I go into the sub directories (students, courses, teachers) and grab their respective .less files to gulp-less + minify?

This is what I have:

gulp.task('less', function () {
  gulp.src('assets/less/*.less')
    .pipe(plumber())
    .pipe(less())
    .pipe(cssmin())
    .pipe(rename({
      suffix: '.min'
    }))
    .pipe(gulp.dest('assets/css/'))
});

Solution

  • You can use **/*.less to match all subdirectories.

    gulp.task('less', function () {
      gulp.src('assets/less/**/*.less')
        .pipe(plumber())
        .pipe(less())
        .pipe(cssmin())
        .pipe(rename({
          suffix: '.min'
        }))
        .pipe(gulp.dest('assets/css/'))
    });