John Cheesman

Gulp Recipes: Scripts Task

Code

An example of using Gulp to process JavaScript files.

Using a build system like Gulp allows you to build a maintainable structure for your JavaScript, keeping vendor code separate and your own files small and modular.

Ingredients

Method

// Dependencies
var gulp   = require('gulp'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify');

// Paths object
var paths = {
    sources: {
        scripts: 'assets/js/**/*.js'
    },
    destinations: {
        scripts: 'js'
    }
};

// Scripts task
gulp.task('scripts', function() {
    gulp.src(paths.sources.scripts)
         .pipe(concat('scripts.js'))
         .pipe(uglify())
         .pipe(gulp.dest(paths.destinations.scripts));
});