我刚刚开始使用gulp,需要我想要使用的所有插件,并编写第一个任务进行sass编译。它似乎工作,但有两个问题,首先当我在命令行上输入gulp时,似乎需要3或4秒才能启动,这似乎比grunt慢(我开始使用gulp,因为我知道它更快)。这是正常的吗?
主要问题是我有一个调用sass任务的默认任务。命令行输出似乎表明两者都在运行,这意味着sass被编译两次。它还输出了我的两次gulp-notify通知,这看起来并不正确。
这是命令行输出...
λ 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
这是我的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']);
有人知道这里发生了什么吗?我误解了Gulp任务的工作原理吗?
答案 0 :(得分:18)
如果您只需要每个流一个通知,请使用gulp-notify的onLast
选项:
//...
.pipe(notify({message: 'Css created', onLast: true}));