【问题标题】:Gulp watch all LESS files in rootGulp 监视根目录下的所有 LESS 文件
【发布时间】:2016-03-10 21:07:02
【问题描述】:

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

当我在项目目录中运行 $ gulp watch 时,它会挂起。开始任务并且永远不会完成。

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 gulp-watch


    【解决方案1】:

    你犯了一些错误

    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-lessgulp,尤其是gulp-watch,只是为了让你的理解更清楚。

    希望对你有帮助

    谢谢

    【讨论】:

    • 更新了我的代码以反映您的建议。仍然挂起。 [14:48:16] 使用 gulpfile ~/Sites/gdw/thedentalsitecontent/themes/gulpfile.js [14:48:16] 开始“观看”...
    • @JustinWHall 当你按下保存时它会重新运行compileCurrentTheme 任务吗? 启动任务并且永远不会完成 - 因为 gulp 正在等待您的更改,这就是它没有完成的原因。这是正常行为
    • 实际上,这行得通。看来 gulp 正在挂断该目录中的其他内容。
    • 没有。我可以手动运行 compileCurrentTheme 任务。 watch 任务挂起。
    • 其实我之前说的不对。有用。 watch 任务只需要很长时间才能运行。这个项目的根目录中有几百个目录。有没有办法将它们从手表中排除,以便执行得更快?所以只看根目录?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多