Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active August 29, 2015 14:18
Show Gist options
  • Save jpotts18/672af1b0f1cca7e5ba6c to your computer and use it in GitHub Desktop.
Save jpotts18/672af1b0f1cca7e5ba6c to your computer and use it in GitHub Desktop.
Starter Gist
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-minify-css gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var fs = require('fs'),
gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
minifyHTML = require('gulp-minify-html'),
del = require('del'),
awspublish = require('gulp-awspublish');
// Styles
gulp.task('styles', function() {
return gulp.src('src/styles/application.scss')
.pipe(sass({ style: 'expanded', }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/styles')) // write unminified
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('dist/styles')) // write minified
});
// Scripts
gulp.task('scripts', function() {
return gulp.src('src/scripts/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
});
// Images
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('dist/images'))
});
// HTML
// minify new or changed HTML pages
gulp.task('html', function() {
gulp.src('src/*.html')
.pipe(minifyHTML())
.pipe(gulp.dest('./dist'));
});
// Clean
gulp.task('clean', function(cb) {
del(['dist'], cb)
});
// Deploy
gulp.task('deploy', function() {
var aws = JSON.parse(fs.readFileSync('aws.json'));
var publisher = awspublish.create(aws);
return gulp.src('dist/**')
// publisher will add Content-Length, Content-Type and headers specified above
// If not specified it will set x-amz-acl to public-read by default
.pipe(publisher.publish())
// print upload updates to console
.pipe(awspublish.reporter());
});
// Default task
gulp.task('default', ['styles', 'scripts', 'images', 'html'], function() {
// Watch .scss files
gulp.watch('src/styles/application.scss', ['styles']);
// Watch .js files
gulp.watch('src/scripts/**/*.js', ['scripts']);
// Watch image files
gulp.watch('src/images/**/*', ['images']);
// Watch html files
gulp.watch('src/**/*.html', ['html']);
// // Create LiveReload server
// livereload.listen();
// // Watch any files in dist/, reload on change
// gulp.watch(['dist/**']).on('change', livereload.changed);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment