我和Gulp一直有一个奇怪的问题。首先来看我的gulpfile:
var gulp = require('gulp'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
less = require('gulp-less'),
lessPluginAutoprefix = require('less-plugin-autoprefix'),
minifyCSS = require('gulp-minify-css');
autoprefix = new lessPluginAutoprefix({browsers: ["> 0%"] });
gulp.task('webserver', function() {
connect.server({
port: 8000,
livereload: true,
root: ['src']
});
});
gulp.task('livereload', function() {
var watchedFiles = [
'src/html/**/*.html',
'src/style/**/*min.css',
'src/javascript/**/*.js'
];
gulp
.src(watchedFiles)
.pipe(watch(watchedFiles))
.pipe(connect.reload());
});
gulp.task('less', function() {
return gulp
.src('src/style/less/main.less')
.pipe(plumber(function(err) {
console.log(err.toString());
this.emit('end');
}))
.pipe(less({
plugins: [autoprefix]
}))
.pipe(gulp.dest('src/style'));
});
gulp.task('minifyCSS', ['less'], function() {
return gulp
.src(['src/style/**/*.css', '!./src/style/**/*.min.*'])
.pipe(minifyCSS({advanced: true}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('src/style'));
});
gulp.task('watch', function() {
gulp
.watch('src/style/less/**/*.less', ['less', 'minifyCSS']);
});
gulp.task('default', ['less', 'minifyCSS', 'webserver', 'livereload', 'watch']);
正如您所看到的,这是一个简单的项目,它可以设置Web服务器,监视某些文件,并相应地执行较少的编译或Web服务器重新加载。一切运行正常,除了返回流的任务(less和minifyCSS),随着时间的推移变得越来越慢,让我在一些观察文件被修改后显示执行时间:
[11:58:24] Starting 'less'...
[11:58:24] Finished 'less' after 67 ms
[11:58:24] Starting 'minifyCSS'...
[11:58:24] Finished 'minifyCSS' after 56 ms
[11:58:25] Starting 'less'...
[11:58:25] Finished 'less' after 126 ms
[11:58:25] Starting 'minifyCSS'...
[11:58:26] Finished 'minifyCSS' after 319 ms
[11:58:26] Starting 'less'...
[11:58:27] Finished 'less' after 138 ms
[11:58:27] Starting 'minifyCSS'...
[11:58:27] Finished 'minifyCSS' after 121 ms
[11:58:29] Starting 'less'...
[11:58:29] Finished 'less' after 227 ms
[11:58:29] Starting 'minifyCSS'...
[11:58:29] Finished 'minifyCSS' after 263 ms
[11:58:30] Starting 'less'...
[11:58:30] Finished 'less' after 176 ms
[11:58:30] Starting 'minifyCSS'...
[11:58:30] Finished 'minifyCSS' after 226 ms
[11:58:31] Starting 'less'...
[11:58:32] Finished 'less' after 370 ms
[11:58:32] Starting 'minifyCSS'...
[11:58:32] Finished 'minifyCSS' after 271 ms
[11:58:33] Starting 'less'...
[11:58:33] Finished 'less' after 135 ms
[11:58:33] Starting 'minifyCSS'...
[11:58:33] Finished 'minifyCSS' after 277 ms
[11:58:34] Starting 'less'...
[11:58:35] Finished 'less' after 240 ms
[11:58:35] Starting 'minifyCSS'...
[11:58:35] Finished 'minifyCSS' after 552 ms
[11:58:36] Starting 'less'...
[11:58:36] Finished 'less' after 159 ms
[11:58:36] Starting 'minifyCSS'...
[11:58:36] Finished 'minifyCSS' after 382 ms
[11:58:37] Starting 'less'...
[11:58:38] Finished 'less' after 344 ms
[11:58:38] Starting 'minifyCSS'...
[11:58:38] Finished 'minifyCSS' after 603 ms
[11:58:39] Starting 'less'...
[11:58:39] Finished 'less' after 186 ms
[11:58:39] Starting 'minifyCSS'...
[11:58:40] Finished 'minifyCSS' after 492 ms
[11:58:41] Starting 'less'...
[11:58:41] Finished 'less' after 414 ms
[11:58:41] Starting 'minifyCSS'...
[11:58:42] Finished 'minifyCSS' after 665 ms
[11:58:42] Starting 'less'...
[11:58:42] Finished 'less' after 312 ms
[11:58:42] Starting 'minifyCSS'...
[11:58:43] Finished 'minifyCSS' after 551 ms
[11:58:44] Starting 'less'...
[11:58:45] Finished 'less' after 365 ms
[11:58:45] Starting 'minifyCSS'...
[11:58:45] Starting 'less'...
[11:58:46] Finished 'minifyCSS' after 1.07 s
[11:58:46] Finished 'less' after 358 ms
[11:58:47] Starting 'less'...
[11:58:48] Finished 'less' after 415 ms
[11:58:48] Starting 'minifyCSS'...
[11:58:49] Finished 'minifyCSS' after 971 ms
它越来越慢,修改任何文件需要很长时间才能在浏览器中刷新,这可能是什么问题?
最好的问候。