Skip to content

Instantly share code, notes, and snippets.

@AlekseyKorzun
Created May 17, 2016 00:01
Show Gist options
  • Save AlekseyKorzun/c5ef0d4dc727b4a217dcf81bde7b6f7a to your computer and use it in GitHub Desktop.
Save AlekseyKorzun/c5ef0d4dc727b4a217dcf81bde7b6f7a to your computer and use it in GitHub Desktop.
Sample gulpfile.js
// Include gulp and plugins
var gulp = require('gulp'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
hologram = require('gulp-hologram'),
filter = require('gulp-filter'),
fs = require('fs'),
rev = require('gulp-rev'),
sass = require('gulp-ruby-sass'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
eslint = require('gulp-eslint'),
insert = require('gulp-insert');
// Configuration variables
var responsive = '/www/site/responsive';
// SCSS
gulp.task('scss', function() {
return gulp.src(responsive + '/build/scss/*.scss')
.pipe(sass({'sourcemap=none': true}))
.on('error', function (err) { console.log(err.message); })
.pipe(gulp.dest(responsive + '/build/css'));
});
gulp.task('styles', function() {
return gulp.src(responsive + '/build/css/responsive.css')
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(rename({basename: 'main', suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(responsive + '/dist/css'))
.pipe(filter('**/*.css'))
.pipe(reload({stream:true}));
});
// JavaScript
gulp.task('scripts', function() {
return gulp.src(responsive + '/build/js/*.js')
.pipe(eslint({
rules: {
'quotes' : 0,
'eol-last' : 0,
'no-undef' : 0,
'no-trailing-spaces' : 0,
'eqeqeq' : 0,
'strict' : 0,
'no-unused-expressions' : 0,
'camelcase' : 0,
'no-redeclare' : 0,
'key-spacing' : 0,
'new-cap' : 0,
'no-use-before-define' : 0,
'no-shadow' : 1,
'no-loop-func' : 1,
'no-alert' : 0,
'no-underscore-dangle' : 0,
'no-unused-vars' : [2, {'vars': 'all', 'args' : 'none'}]
},
globals: {
'jQuery' : false,
'undefined' : false,
'window' : false
}
}))
.pipe(eslint.format())
.pipe(concat('global.js'))
.pipe(gulp.dest(responsive + '/dist/js/'))
.pipe(uglify())
.on('error', function(e) { console.log('\x07',e.message); return this.end(); })
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(responsive + '/dist/js/'))
.pipe(reload({stream:true}));
});
gulp.task('libs', function() {
return gulp.src(responsive + '/lib/*.js')
.pipe(concat('libraries.js'))
.pipe(gulp.dest(responsive + '/dist/js/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.on('error', function(e) { console.log('\x07',e.message); return this.end(); })
.pipe(gulp.dest(responsive + '/dist/js/'))
.pipe(reload({stream:true}));
});
// Browser-sync stuff
gulp.task('browser-sync', function() {
browserSync({
proxy: '__LOCAL__.__DOMAIN__.com'
});
});
// Clean-up
gulp.task('clean', function() {
return gulp
.src(responsive + '/dist/**/*', {read: false})
.pipe(clean({force: true}));
});
// Must call this before commiting to production
gulp.task('fingerprint', function () {
return gulp
.src([responsive + '/js/libraries.min.js', responsive + '/dist/js/global.min.js', responsive + '/dist/css/global.css'], {base: responsive + '/dist'})
.pipe(gulp.dest(responsive + '/dist'))
.pipe(rev())
.pipe(gulp.dest(responsive + '/dist'))
.pipe(rev.manifest())
.pipe(gulp.dest(responsive + '/dist'));
});
gulp.task('removeOldAssets', ['fingerprint'], function () {
return gulp
.src([responsive + '/dist/js/libraries.js', responsive + '/dist/js/global.min.js', responsive + '/dist/js/libraries.min.js', responsive + '/dist/css/global.min.css'], {read: false})
.pipe(clean());
});
gulp.task('deploy', ['removeOldAssets']);
// Watch all these things
gulp.task('watch', function () {
gulp.watch(responsive + '/build/scss/**/*', ['scss']);
gulp.watch(responsive + '/build/css/*.css', ['styles']);
gulp.watch(responsive + '/build/js/*.js', ['scripts']);
});
gulp.task('default', ['browser-sync','watch','scripts','scss', 'styles', 'libs']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment