Default function of Gulp

Asked

Viewed 54 times

0

I would like to make the "tasks" below run simultaneously, as I should proceed?

var gulp = require('gulp')
,clean = require('gulp-clean')
,imagemin = require('gulp-imagemin')
,cleanCSS = require('gulp-clean-css')
,minify = require('gulp-minify')
,inlinesource = require('gulp-inline-source')
,htmlmin = require('gulp-htmlmin')
,browserSync = require ('browser-sync');

gulp.task('copy', function(){
	return gulp.src('src/**/*')
        .pipe(gulp.dest('./dist'));
});

gulp.task('clean',function(){
	return gulp.src('./dist')
        .pipe(clean());
});

exports.buildImg = () => (
    gulp.src('./dist/imagens/**/*.+(png|jpg|gif|jpeg)')
        .pipe(imagemin())
        .pipe(gulp.dest('./dist/imagens'))
);

gulp.task('minify-css', () => {
    return gulp.src('./src/css/**/*.css')
      .pipe(cleanCSS())
      .pipe(gulp.dest('./dist/css'));
});

gulp.task('minify-js', function(cb) {
    gulp.src(['./src/scripts/**/*.js'])
      .pipe(minify())
      .pipe(gulp.dest('./dist/scripts'))
      cb();
});

gulp.task('inline', function () {
    return gulp.src('./dist/**/*.html')
        .pipe(inlinesource())
        .pipe(gulp.dest('./dist'));
});

gulp.task('minify-html', () => {
    return gulp.src('src/*.html')
      .pipe(htmlmin({ collapseWhitespace: true }))
      .pipe(gulp.dest('./dist'));
});

  • But why should they run simultaneously? Isn’t it better sequentially? Especially since it seems that some of the processes depend on the previous ones? What I could solve with gulp.series or runSequence. Already if it were to run simultaneously (q seems to me to be the sense of parallel) would use the gulp.parallel

  • Yes William, I believe that sequentially it would be ideal, as I should proceed please?

  • Are you using Gulp 3.9 or Gulp 4.0 (this is very new, I haven’t migrated my projects with Gulp pro 4 yet)? If you do not know type in the terminal or cmd to access the project folder and type gulp --version, takes the version of "local Gulp"

  • I was using the 4.0, with the 3.9 everything was beautiful, when I migrated I had some problems,

  • The gulp.series() solves pro 4.0, if it is 3.9 you will have to install runSequence

1 answer

0

Add this line at the end of the code to set all tasks specified as default:

gulp.task('default', gulp.series('copy', 'clean', 'minify-css', 'minify-js', 'inline', 'minify-html'));

After that just type Gulp that by default all tasks will be executed

  • Thank you Mohamad, I will try and give you a return.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.