1

I have the following two tasks:

gulp.task('compress', () => {
    return gulp.src('app/static/angular/**/*.js')
        .pipe(concat('build.js'))
        .pipe(gulp.dest('./app/static'));
});

gulp.task('templates', () => {
    return gulp.src('app/static/angular/**/*.html')
        .pipe(htmlmin())
        .pipe(angularTemplateCache('templates.js', {
            module: 'myApp',
            root: '/static/angular'
        }))
        .pipe(gulp.dest('./app/static'))
});

And it works fine, but I want them both concatenated into build.js -- how can I combine these two?

2 Answers 2

1

In the end I used merge-stream to merge the two streams into one output file:

var gulp = require('gulp');
var concat = require('gulp-concat');
var htmlmin = require('gulp-htmlmin');
var angularTemplateCache = require('gulp-angular-templatecache');
var merge = require('merge-stream');

gulp.task('build', () => {
    var code = gulp.src('app/static/angular/**/*.js');

    var templates = gulp.src('app/static/angular/**/*.html')
        .pipe(htmlmin())
        .pipe(angularTemplateCache({
            module: 'myApp',
            root: '/static/angular'
        }));

    return merge(code, templates)
        .pipe(concat('build.js'))
        .pipe(gulp.dest('./app/static'));
});

gulp.task('default', ['build']);
Sign up to request clarification or add additional context in comments.

Comments

0

I assume the above task mentioned is in separate file say compress.js inside tasks folder

In gulpfile.js you can use below code :

//Include require-dir to include files available in tasks directory

var requireDir = require('require-dir');

// And Take the tasks directory

requireDir('./tasks');

Then you can create a build task as below in gulpfile.js:

gulp.task('build', ['compress', 'templates']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.