Friday, 15 May 2015

javascript - Gulp callback - How to tell Gulp to run a task first before another? -



javascript - Gulp callback - How to tell Gulp to run a task first before another? -

how can tell gulp run task first before another?

for instance, need crunch .less file .css first,

// crunch less css. gulp.task('less', function () { homecoming gulp.src([ 'css/myless.less' ]) .pipe(less().on('error', function (err) { console.log(err); })) .pipe(cssmin().on('error', function(err) { console.log(err); })) .pipe(rename({suffix: '.less'})) .pipe(gulp.dest('css/')); });

then concat other normal .css files,

var concat = require('gulp-concat'), minifycss = require('gulp-minify-css'), clean = require('gulp-clean'); // css concat, auto-prefix , minify gulp.task('styles', function() { gulp.src([ 'css/myless.less.css', 'css/normal.css' ]) .pipe(concat('main.css')) .pipe(minifycss()) .pipe(gulp.dest('css/')); });

run task,

gulp.task('default', ['less', 'styles'], function() { })

it optimise 'css/normal.css', not not concat 'css/myless.less.css'.

what should do?

your styles task should depend on less 1 wait completion. doing did run 2 tasks in parallel.

you can specify array of dependent task on each task of gulpfile:

gulp.task('styles', ['less'], function () {

then defaulttask should this:

gulp.task('default', ['styles']);

javascript css asynchronous less gulp

No comments:

Post a Comment