Gulp任务似乎在运行两次,而不是一次 [英] Gulp tasks appear to be running twice, instead of once

查看:65
本文介绍了Gulp任务似乎在运行两次,而不是一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gulp任务似乎正在运行两次而不是一次,试图解决这一问题,我认为有些人建议罪魁祸首可能在Gulpfile.js

My gulp tasks seem to be running twice instead of once, trying to fix thatI think some have suggested that the culprit might lie in the default task in Gulpfile.js

// Include Gulp
var gulp = require('gulp');

// All of your plugins
var autoprefixer = require('gulp-autoprefixer');
var imagemin = require('gulp-imagemin');
var jshint = require('gulp-jshint');
var livereload = require('gulp-livereload');
var minify = require('gulp-minify-css');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');

// Compile CSS, Autoprefix
gulp.task('styles', function() {
  return gulp.src('assets/css/style.scss')
    .pipe(sass({ style: 'expanded' }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('assets/css'))
    // .pipe(rename({suffix: '.min'}))
    // .pipe(minify())
    .pipe(gulp.dest('assets/css'))
    .pipe(notify({ message: "Watson: I've organized your files for you." }));
});

// Lint, Concatenate and Minify JavaScript
gulp.task('scripts', function() {
  return gulp.src('assets/js/scripts.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'))
    // .pipe(concat('scripts.js'))
    .pipe(gulp.dest('assets/js'))
    // .pipe(rename({suffix: '.min'}))
    // .pipe(uglify())
    .pipe(gulp.dest('assets/js'))
    .pipe(notify({ message: "Watson: I've done your dirty laundry." }));
});

// Watch files for changes
gulp.task('watch', function() {
    gulp.watch('assets/js/*.js', ['scripts', 'styles']);
    gulp.watch('assets/css/**/*.scss', ['styles']);
});

// Default Task
gulp.task('default', function() {
    gulp.start('styles', 'scripts', 'watch');
});

终端

[18:53:57] Using gulpfile ~/Desktop/Projects/legislature/Gulpfile.js
[18:53:57] Starting 'default'...
[18:53:57] Starting 'styles'...
[18:53:57] Starting 'scripts'...
[18:53:58] Starting 'watch'...
[18:53:58] Finished 'watch' after 26 ms
[18:53:58] Finished 'default' after 49 ms
[18:53:58] gulp-notify: [Gulp notification] Watson: I've organized your files for you.
[18:53:58] Finished 'styles' after 262 ms
[18:53:58] gulp-notify: [Gulp notification] Watson: I've done your dirty laundry.
[18:53:58] Finished 'scripts' after 256 ms
[18:53:58] Starting 'scripts'...
[18:53:58] Starting 'styles'...
[18:53:58] gulp-notify: [Gulp notification] Watson: I've done your dirty laundry.
[18:53:58] Finished 'scripts' after 232 ms
[18:53:58] gulp-notify: [Gulp notification] Watson: I've organized your files for you.
[18:53:58] Finished 'styles' after 232 ms

推荐答案

您的问题是:您有两个相同的行来保存文件并触发两次.

Your problem is: you have two identical line that saves the file and triggers twice.

在您的脚本任务中

.pipe(gulp.dest('assets/js'))

新来者可能遇到的其他问题.
我在这里写我的经验可能会对某人有所帮助.

Other possible problem for newcomers.
I write here my experience maybe helps somebody.

我将Dropbox用于我的项目并在那里工作.当Dropbox打开时,任务会运行两次,因为Dropbox会检测到文件更改并执行某些操作.特别是Typescript文件,我不知道为什么.

I use Dropbox for my project and work there. When Dropbox is open, tasks run twice because Dropbox detects file change and does something. Specially Typescript files, i don't know why.

这篇关于Gulp任务似乎在运行两次,而不是一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆