简体   繁体   English

Gulp文件运行任务并通知两次

[英]Gulp file running tasks and notifying twice

I've just started using gulp for the first time, required all the plugins I want to use and written the first task for sass compilation. 我刚刚开始使用gulp,需要我想要使用的所有插件并编写第一个用于sass编译的任务。 It seems to work but there are two problems, firstly when I type gulp on the command line it seems to take 3 or 4 seconds to start which seems slower than grunt (I started using gulp because I understood it was faster). 它似乎工作,但有两个问题,首先当我在命令行上输入gulp时,似乎需要3或4秒才能启动,这似乎比grunt慢(我开始使用gulp,因为我知道它更快)。 Is this normal? 这是正常的吗?

The main problem though is that I have a default task which calls the sass task. 但主要的问题是我有一个调用sass任务的默认任务。 The command line output seems to suggest that both are being run which means the sass is being compiled twice. 命令行输出似乎表明两者都在运行,这意味着sass被编译两次。 It is also outputting my single gulp-notify notification twice which doesn't seem right. 它也输出我的两次gulp-notify通知,这似乎不对。

Here is the command line output... 这是命令行输出...

λ gulp default
[00:53:40] Using gulpfile ~\Desktop\jon\gulpfile.js
[00:53:40] Starting 'sass'...
[00:53:40] Finished 'sass' after 10 ms
[00:53:40] Starting 'default'...
[00:53:40] Finished 'default' after 7.93 μs
[00:53:41] gulp-notify: [Gulp notification] Css created
[00:53:41] gulp-notify: [Gulp notification] Css created

And here is my gulp file in full... 这是我的gulp文件全部...

var gulp = require('gulp'),
    gutil = require('gulp-util'),
    compass = require('gulp-compass'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    watch = require('gulp-watch'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    jshint = require('gulp-jshint'),
    autoprefixer = require('gulp-autoprefixer'),
    minifyCSS = require('gulp-minify-css'),
    traceur = require('gulp-traceur'),
    svgmin = require('gulp-svgmin'),
    imagemin = require('gulp-imagemin'),
    ngAnnotate = require('gulp-ng-annotate'),
    expect = require('gulp-expect-file'),
    sourcemaps = require('gulp-sourcemaps');

var paths = {
    src: "src",
    css: "stylesheets",
    img: "images",
    js:  "js"
}


// Compile Our Sass
gulp.task('sass', function() {

    gulp.src(paths.src + '/sass/*.scss')
        .pipe(sourcemaps.init())
        .pipe(compass({
            sass: 'src/sass',
            environment: 'development',
            outputStyle: 'expanded',
            debugInfo: false,
            noLineComments: true
        }))
        .pipe(autoprefixer('> 5%', 'last 2 version', 'ie 9'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(paths.css))
        .pipe(notify({ message: 'Css created' }));

});


// Dev Task
gulp.task('default', ['sass']);

Anybody know what's going on here? 谁知道这里发生了什么? Have I misunderstood how Gulp tasks work? 我误解了Gulp任务是如何工作的吗?

Use the onLast option of gulp-notify if you only want a single notification per-stream: 如果您只需要每个流的单个通知,请使用onLast -notify的onLast选项:

//...
.pipe(notify({message: 'Css created', onLast: true}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM