我刚刚开始使用Gulp来改进我的工作流程。我目前有一个名为styles
编译.less
文件的任务和一个名为 的任务watch
,用于监视任何.less
文件中的更改,然后运行styles
任务。我的gulpfile.js
包含以下代码:
var gulp = require( 'gulp' ),
less = require( 'gulp-less' ),
autoprefixer = require( 'gulp-autoprefixer' ),
minifycss = require( 'gulp-minify-css' ),
jshint = require( 'gulp-jshint' ),
uglify = require( 'gulp-uglify' ),
imagemin = require( 'gulp-imagemin' ),
rename = require( 'gulp-rename' ),
clean = require( 'gulp-clean' ),
concat = require( 'gulp-concat' ),
notify = require( 'gulp-notify' ),
cache = require( 'gulp-cache' ),
header = require( 'gulp-header' ),
footer = require( 'gulp-footer' );
// styles task
gulp.task( 'styles', function() {
return gulp.src( 'src/styles/main.less' )
.pipe( less({ paths: ['src/styles/'] }) )
.pipe( autoprefixer( 'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4' ) )
.pipe( gulp.dest( 'dist/assets/css' ) )
.pipe( rename( 'main.min.css' ) )
.pipe( minifycss() )
.pipe( gulp.dest( 'dist/assets/css' ) )
.pipe( notify({ message: 'Styles task complete' }) );
} )
(...)
// watch task
gulp.task('watch', function() {
// Watch .less files
gulp.watch('src/styles/**/*.less', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
gulp.run('styles');
});
});
问题是,当我运行时gulp watch
,它会启动任务并在styles
我第一次更改.less
文件时运行任务。第一次之后,我只记录了消息(File X was changed, running tasks...
)。难道我做错了什么?
感谢您的任何提示或帮助!
编辑
只是根据要求提供一些信息:我正在运行Node.js 0.10.24和Gulp 3.4.0。下面是提示输出的截图: