Created
May 15, 2015 04:53
-
-
Save heyjordn/5751fbd1cdd88ee321bc to your computer and use it in GitHub Desktop.
Common build and optimizing tasks using Gulp.js (minify JS, minify CSS and optimize images for web)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var uglify = require('gulp-uglify'); | |
var imagemin = require('gulp-imagemin'); | |
var rename = require('gulp-rename'); | |
var cssmin = require('gulp-cssmin'); | |
/* | |
*Command: gulp uglify | |
* Minifies or "uglifies" JavaScript files for faster load time. | |
*/ | |
gulp.task('uglify', function() { | |
return gulp.src('js/*.js') | |
.pipe(uglify()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest('dist/js')); | |
}); | |
/* | |
*Command: gulp cssmin | |
* Minifies CSS files for faster load time. | |
*/ | |
gulp.task('cssmin', function() { | |
return gulp.src('css/*.css') | |
.pipe(cssmin()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest('dist/css')); | |
}) | |
/* | |
*Command: gulp imagemin | |
* Compresses and optimizes images with gulp-imagemin | |
* progressive - jpg | |
* interlaced - gif | |
* multipass - svg | |
*/ | |
gulp.task('imagemin', function() { | |
return gulp.src('img/*') | |
.pipe(imagemin({ | |
progressive: true, | |
interlaced: true, | |
multipass: true | |
})) | |
.pipe(gulp.dest('dist/img')); | |
}) | |
gulp.task('default', function() { | |
gulp.start(['uglify', 'imagemin', 'cssmin']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment