Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp running dependencies in parallel #670

Closed
LandonSchropp opened this issue Sep 7, 2014 · 3 comments
Closed

Gulp running dependencies in parallel #670

LandonSchropp opened this issue Sep 7, 2014 · 3 comments

Comments

@LandonSchropp
Copy link

I'm trying to write a simple build system with Gulp. I'm using Gulp 3.8.7. Here's my gulpfile.js:

var gulp = require('gulp');
var clean = require('gulp-clean');
var sass = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var rename = require("gulp-rename");

gulp.task('clean', function() {
  return gulp.src('build/**/*', {read: false})
    .pipe(clean());
});

gulp.task('compile', function() {
  return gulp.src('source/griddle.sass')
    .pipe(sass({style: 'expanded', lineNumbers: true}))
    .pipe(autoprefixer('last 2 versions', '> 1%', 'ie >= 10'))
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('build'));
});

gulp.task('minify', function() {
  return gulp.src('build/griddle.css')
    .pipe(minifyCSS())
    .pipe(rename("griddle.min.css"))
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('build'));
});

gulp.task('default', [ 'clean', 'compile', 'minify' ]);

Every other time I run gulp, I get the following error:

[14:11:19] Using gulpfile ~/Development/griddle/gulpfile.js
[14:11:19] Starting 'clean'...
[14:11:19] Starting 'build'...
[14:11:19] Starting 'minify'...
[14:11:19] Finished 'clean' after 23 ms

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open '/Users/landonschropp/Development/griddle/build/griddle.css'

It looks like Gulp is running clean, compile and minify in parallel, even though the tasks are dependent. Am I missing something?

@pkozlowski-opensource
Copy link
Contributor

Nope, you are right, all the deps are run in parallel which is desirable in most cases to maximise performance. Still, there are cases where the very nature of tasks calls for serial execution. There are some work-arounds to achieve this in the current version of gulp (https://www.npmjs.org/package/run-sequence) but it is something that is going to be handled very elegantly in Gulp 4, see #355

@mallowigi
Copy link

This is because gulp run in maximum concurrency, so you cannot be sure that minify run once and only after clean and build.

This should be fixed in the runSeries improvement of gulp 4, but for the time being, you should take a look at run-sequence (https://www.npmjs.org/package/run-sequence)

@LandonSchropp
Copy link
Author

Ah, I see. Thanks for the lightning fast replies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants