Gulp task runs once, executes twice

249 Views Asked by At

I'm using Gulp to compile stylus, but the task seems to run twice making gulp-notify trip.

Here's my gulpfile.js

var gulp, plugins;

gulp = require('gulp');
plugins = require('gulp-load-plugins')();


/**
 * Watch for changes on stylus files, when detecting change run stylus task
 * @return {void}
 */
gulp.task('watch-stylus', function() {
  gulp.src('./app/Resources/stylus/**/*.styl')
      .pipe(plugins.plumber())
      .pipe(plugins.watch('./app/Resources/stylus/**/*.styl', {
        verbose: true,
        readDelay: 0
      }))
      .pipe(plugins.exec('gulp stylus'))
      .pipe(plugins.notify("Stylus compiled"))
      .pipe(plugins.plumber.stop());
});

/**
 * Compile stylus and auto prefix the compiled css
 * @return {void}   
 */
gulp.task('stylus', function() {
  gulp.src(['./app/Resources/stylus/**/*.styl', '!./app/Resources/stylus/**/_*.styl'])
    .pipe(plugins.plumber())
    .pipe(plugins.stylus())
    .pipe(plugins.autoprefixer({
        browsers: ['last 2 versions'],
        cascade: false
      }))
    .pipe(plugins.plumber.stop())
    .pipe(gulp.dest('web/css'));
});

Things I've checked

  • No multiple dests.
  • Input and output dir are different.

Image: One file change

The plugins I'm using

  • gulp-load-plugins to load the plugins
  • gulp-watch to watch for file changes
  • gulp-notify to notify stylus has been compiled
  • gulp-stylus to compile stylus
  • gulp-exec to run compile task even when a partial was edited
  • gulp-autoprefixer to prefix css
  • gulp-plumber so gulp-watch doesn't die on error
0

There are 0 best solutions below