0

I want to have a gulp task in Visual Studio Code which watches all files in a folder called less with the extension .less. When found, a task must compile the less files to a folder called css on the same level as the less folder.

Current code:

  
gulp.task('less', function() {
    gulp.src('less/*.less',{ cwd:'..' })
        .pipe(less())
        .pipe(gulp.dest( 'css' ), { cwd:'..' });
});

gulp.task('default', function() {
    gulp.watch('./**/less/*.less', ['less']);
}); 

What I want:

  • x
    • y
    • less
      • style.less
    • css
      • style.css

What above code does:

  • x
    • y
    • less
      • style.less
  • css
    • y
      • less
        • style.css

I had this working when being specific in the path, but the problem is that i've less folders on multiple levels. How can I solve this?

  • That creates the css file in the same folder as the less files. I want that the css files are in the folder called css on the same level as the folder called less. – user2425360 Nov 04 '15 at 06:49

3 Answers3

3

I know this is bit old question, but felt worth sharing my answer.

gulp.task('app:less', [], function () {
return gulp.src(['./src/**/*.less'], { base: './src/' })
    .pipe(less())
    .pipe(gulp.dest('./src/'));
});

Setting base option to root folder with dest path to ./src/ worked for me.

Thaadikkaaran
  • 5,088
  • 7
  • 37
  • 59
0

Currently there is no way to do it. The only thing which could approach you to a solution is gulp-flatten. However, this requires to specify a fixed number of parents to include. In your case, where you have folders in different levels, you'd need to specify a different number for each case. So, the only option would be to modify the flatten code to support something like an excludeParents, which does the contrary that flatten, i.e exclude a fixed number of parents (in your case, 1).

JotaBe
  • 38,030
  • 8
  • 98
  • 117
0

Try this :

gulp.task('less', function() {
    gulp.src(['**/*.less', *.less],{ cwd:'less' })
        .pipe(less())
        .pipe(gulp.dest('css'));
});
Arnaud Gueras
  • 2,014
  • 11
  • 14