Gulp 在 Windows 上的运行速度比在 Mac 上慢 4 倍。我已经添加了 gulp 文件以及下面的命令行输出。gulpfile 非常简单。
这是命令行输出:
$ gulp
[14:00:06] Using gulpfile c:\gulpSample\gulpfile.js
[14:00:06] Starting 'scripts'...
[14:00:07] Finished 'scripts' after 26 ms
[14:00:07] Starting 'watch'...
[14:00:07] Finished 'watch' after 30 ms
[14:00:07] Starting 'default'...
[14:00:07] Finished 'default' after 23 μs
Mac 上的速度通常快 4 倍
这是 gulp 文件:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var sass = require('gulp-ruby-sass');
//var plumber = require('gulp-plumber');
//scripts Task
//uglifies
function errorLog(error){
console.error.bind(error);
this.emit('end');
}
gulp.task('scripts', function(){
gulp.src('js/*.js')
//.pipe(plumber())
.pipe(uglify())
.on('error', errorLog)
.pipe(gulp.dest('build/js'));
});
//Watch Task
gulp.task('watch', function(){
gulp.watch('js/*.js',['scripts']);
gulp.watch('scss/*.scss',['styles']);
});
gulp.task('default',['scripts','watch']);
最佳答案
脚本任务时间执行不正确,因为您需要回调 gulp 才能正确接收流。您发布的执行时间只是 gulp 初始化任务所花费的时间。要修复它,您需要返回流:
gulp.task('scripts', function () {
return gulp.src('js/*.js')
//.pipe(plumber())
.pipe(uglify())
.on('error', errorLog)
.pipe(gulp.dest('build/js'));
});
这应该可以让您更好地了解完成任务实际需要多长时间。
关于javascript - 为什么 gulp 在 Windows 机器上这么慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28097541/