2

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']);
4

1 回答 1

2

脚本任务时间执行不正确,需要回调 gulp 才能正常下沉。您发布的执行时间只是 gulp 初始化任务所需的时间。要修复它,您需要返回流:

gulp.task('scripts', function () {
    return gulp.src('js/*.js')
    //.pipe(plumber())
    .pipe(uglify())
    .on('error', errorLog)
    .pipe(gulp.dest('build/js'));
});

这应该让您更好地了解这些任务实际上需要多长时间才能完成。

于 2015-01-22T21:04:24.110 回答