Skip to content Skip to sidebar Skip to footer

Gulp: Different Pipe Collections Within Same Task (coffeescript And Javascript)

What I've been attempting to do is create one scripts task that takes all .coffee and .js files and does what's needed for each: Coffee files should be run through coffee(), coffe

Solution 1:

I would do this in a 2 tasks row:

  1. Process coffee files (eg: transform them to javascript)
  2. Process javascript files that will wait for the coffee task to proceed before starting

My gulpfile.js would be:

var coffee_files = ['assets/js/src/*.coffee']
var js_files = ['assets/js/src/*.js']

gulp.task('coffee', function() {
    //note the return is very important herereturn gulp.src(coffee_files)
        .pipe(coffee()) //do your pipes//dest to the same folder assuming those are now js files
        .pipe(gulp.dest('assets/js/src')) 
})

gulp.task('javascript', ['coffee'], function() {
    return gulp.src(js_files)
        .pipe(jshint())
        .pipe(minify())
        .pipe(gulp.dest('assets/js/build'))
})

/**
* Now, `gulp` command will first process coffee files, transform them to javascript
* then javascript is executed and minifies stuff to your destination folder
*/
gulp.task('default', ['javascript'])

/**
* `gulp coffee` will only process coffee files
* `gulp javascript` will only process javascript files
* Watching files can be done like this:
*/
gulp.task('watch', function() {
    gulp.watch(coffee_files, ['javascript'])
    gulp.watch(js_files, ['javascript'])
})

Post a Comment for "Gulp: Different Pipe Collections Within Same Task (coffeescript And Javascript)"