Gulp 查看根目录下的所有 LESS 文件

Gulp watch all LESS files in root

查看根gulp 项目目录中的所有less 文件,然后只编译保存的LESS 文件。我无法通过第一部分。

当我运行$gulpwatch在项目目录下挂了。开始任务但永远不会完成。

var gulp = require('gulp');
var less = require('gulp-less');
var path = require('path');

gulp.task('compileCurrentTheme', function () {
 return gulp.src('./*.less')
 .pipe(less({
  compress: true
 }))
 .pipe(gulp.dest('./'));
});

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

你犯了一些错误

gulp.task('compileCurrentTheme', function () {
  return gulp.src('./*.less') // ./ -> root directory
    .pipe(less())
    .pipe(gulp.dest('yourPath')); // you can also type ./ it will create .css files in your root directory
});

// Gulp watch functions
gulp.task('watch:less', function(){
  gulp.watch('./*.less', ['compileCurrentTheme']); 
});

重命名你的watch任务到watch:less然后从你的控制台运行它gulp watch:less

请看gulp-less and gulp,特别是gulp-watch,让你的理解更清楚。

希望对你有所帮助

谢谢