Javascript 为什么gulp在windows机器上速度这么慢?

Javascript 为什么gulp在windows机器上速度这么慢?,javascript,gulp,gulp-watch,Javascript,Gulp,Gulp Watch,Gulp在windows上的运行速度是mac上的4倍。我在下面添加了gulp文件和命令行输出 以下是命令行输出: $ 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:0

Gulp在windows上的运行速度是mac上的4倍。我在下面添加了gulp文件和命令行输出

以下是命令行输出:

$ 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倍

这是吞咽文件:

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'));
});
这将使您更好地了解任务实际完成所需的时间