Search code examples
gulpgulp-watchgulp-uglify

Gulp only executes last task in gulpfile?


I have about six Gulp tasks which are similar to this:

gulp.task('scripts', function() {
    return gulp.src([
        'public_html/assets/plugins/zeroclipboard/ZeroClipboard.min.js',
        'public_html/assets/plugins/redactor/redactor.min.js',
        'public_html/assets/libraries/autobahn.min.js'
    ])
        .pipe(concat('localStatic.js'))
        .pipe(gulp.dest('public_html/assets/dist/js/'))
        .pipe(rename('localStatic.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('public_html/assets/dist/js'));
});

When I run gulp in the terminal, it only executes the last task (or at least, only the JS files from the last task are generated).

Multiple tasks are allowed in Gulp, right? Why would only the last task in the file be executed?


Solution

  • You can run multiple tasks at the same time yes, provided they have different names.

    gulp.task('name', function() {})
    gulp.task('of', function() {})
    // ... task definitions
    gulp.task('default', ['name', 'of', 'the', 'tasks', 'you', 'want', 'to','run']);
    

    This will run all the tasks specified in parallel when you run the gulp command.

    You can read more about task dependencies in the docs