Gulp-watch不起作用,不能运行它

时间:2015-01-13 18:46:49

标签: node.js gulp gulp-watch gulp-less

我有gulpfile.js

var gulp = require('gulp'),
browserSync = require('browser-sync');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var livereload = require('gulp-livereload');
var watch = require('gulp-watch');
var minifycss = require('gulp-minify-css');

gulp.task('browserSync', function () {
  var files = ['app/**'];

 browserSync.init(files, {
    server: {
       baseDir: 'app/',
       index: 'index.html'
    },
   logPrefix: 'Ex02xAth', 
   browser: ['chrome', 'opera', 'firefox']
 });
});

gulp.task('clean', function(){
  return gulp.src('app/tmp/*', {read: false})  
   .pipe(clean());
});

gulp.task('slucovac', function(){
  return gulp.src('app/lib/*.js')
   .pipe(concat('all.js')) 
   .pipe(gulp.dest('app/built/'));
});

gulp.task('komprese', function(){
  return gulp.src('app/lib/*.js')
  .pipe(uglify())
  .pipe(gulp.dest('app/minjs/'));
});

gulp.task('watch', function () {
  var watcher = gulp.watch('app/html/*.tmpl.html', ['build']);
  watcher.on('change', function (event) {
    console.log('Event type: ' + event.type); // added, changed, or deleted
    console.log('Event path: ' + event.path); // The path of the modified file
  });
});

gulp.task('less', function(){
  gulp.src('app/less/*.less')
   .pipe(watch())
   .pipe(less())
   .pipe(gulp.dest('app/css/'))
   .pipe(livereload());
});  

gulp.task('minifycss', function() {
  gulp.src('app/css/*.css')
   .pipe(minifycss())
   .pipe(gulp.dest('app/cssmin/'));
});

gulp.task('default', ['slucovac', 'komprese', 'minifycss', 'browserSync']);

当我运行gulp less命令行时写道:     “插件'gulp-watch'出错。消息:需要glob参数。”

我按照这篇文章继续:http://www.smashingmagazine.com/2014/06/11/building-with-gulp/

我可以寻求帮助吗?感谢

1 个答案:

答案 0 :(得分:8)

您需要指定要观看的文件。 请务必核对documentation

gulp.task('less', function(){
  gulp.src('app/less/*.less')
   .pipe(watch('app/less/*.less'))
   .pipe(less())
   .pipe(gulp.dest('app/css/'))
   .pipe(livereload());
});