Search code examples
javascriptgulpgulp-concatdot.js

Combine gulp tasks to avoid creating the unnecessary files


I'm using two separate gulp tasks to minify templates into js file (1) and concat all js file of the project to the only minified (2).

gulp.task('templates', function() { // RESULT of this task
    return gulp.src('templates/**/*.html')
        .pipe(dotify({
            root : 'templates'
        }))
        .pipe(concat('templates.js'))
        .pipe(gulp.dest('js'));
    });


gulp.task('minifyJs', ['templates'], function() {
    return gulp.src([
        'js/templates.js',
        'js/plugins/*.js',
        'js/*.js'
    ])
    .pipe(concat('scripts-all.js'))
});

The question is: am I able to avoid creating the templates.js file by processing the result from first task to the second one to concat it with the rest of js's?


Solution

  • Solution: addSrc should be used

    return gulp.src('templates/**/*.html')
        .pipe(dotify({
            root : 'templates'
        }))
        .pipe(addSrc([
            'js/plugins/*.js',
            'js/common/*.js',
            'js/ui/*.js',
            'js/pages/*.js',
            'js/*.js'
        ]))
        .pipe(concat('scripts-all.js'))
        .pipe(gulp.dest('js/'));