Last active
August 29, 2015 14:18
-
-
Save AnnamalaiNagappan/00904d906564f8703ebe to your computer and use it in GitHub Desktop.
Gulp Automation
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
/* | |
This command installs gulp (globally) | |
npm install --global gulp | |
The below listed commands should be done in your project/development folder | |
npm install --save-dev gulp | |
npm install --save-dev gulp-minify-css | |
npm install --save-dev gulp-uglify | |
npm install --save-dev gulp-concat-css | |
npm install --save-dev gulp-concat | |
npm install --save-dev gulp-jshint | |
npm install --save-dev gulp-imagemin | |
npm install --save-dev gulp-svgmin | |
npm install --save-dev gulp-minify-html | |
*/ | |
/* | |
Tasks performed by this script: | |
1. Minify the CSS and JavaScript files | |
2. Concatenate the CSS files and JavaScript files | |
3. Lint our JavaScript code to check for errors and issues | |
4. Optimize the images | |
5. Minify the HTML documents | |
Change src and dest wherever required. | |
This file should be placed in your project/development folder and run it by typing | |
gulp | |
*/ | |
var gulp = require('gulp'); | |
gulp.task('default', ['css', 'js', 'img', 'svg', 'html'], function () {}); | |
var minifycss = require('gulp-minify-css'), | |
uglify = require('gulp-uglify'), | |
concatcss = require('gulp-concat-css'), | |
concat = require('gulp-concat'), | |
jshint = require('gulp-jshint'), | |
imagemin = require('gulp-imagemin'), | |
svgmin = require('gulp-svgmin'), | |
minifyhtml = require('gulp-minify-html'), | |
useref = require('gulp-useref'); | |
// CSS minification task | |
gulp.task('css', function() { | |
return gulp.src('css/*.css') | |
.pipe(concatcss('semeano.min.css')) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('dist/css')); | |
}); | |
// JS minification task | |
gulp.task('js', function() { | |
return gulp.src('js/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter("default")) | |
.pipe(concat('semeano.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('dist/js')); | |
}); | |
// Image optimization task | |
gulp.task('img', function () { | |
return gulp.src('images/*.*') | |
.pipe(imagemin()) | |
.pipe(gulp.dest('dist/img')); | |
}); | |
// SVG optimization task | |
gulp.task('svg', function () { | |
return gulp.src('svg/*.svg') | |
.pipe(svgmin()) | |
.pipe(gulp.dest('dist/svg')); | |
}); | |
// Switch URIs to dist files + minify HTML task | |
gulp.task('html', function () { | |
return gulp.src(['*.html']) | |
.pipe(useref()) | |
.pipe(minifyhtml()) | |
.pipe(gulp.dest('dist')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment