Created
June 1, 2014 07:48
-
-
Save Eworm/ac30a455f53b6de99e86 to your computer and use it in GitHub Desktop.
Gulpfile with SCSS lint
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'); | |
// Get packages from package.json | |
var plugins = require("gulp-load-plugins")(); | |
// Livereload stuff | |
lr = require('tiny-lr'), | |
server = lr(); | |
// Set standard paths | |
var paths_src = { | |
compass: './sass/**/*.scss', | |
autoprefixer: '*.css', | |
svgmin: './img-src/*.svg', | |
svg2png: './img-src/*.svg', | |
uglify: ['./bower_components/picturefill/external/matchmedia.js', | |
'./bower_components/picturefill/picturefill.js', | |
'./bower_components/typed.js/js/typed.js', | |
'./js-src/functions-13051541.js'], | |
yepnope: ['./bower_components/yepnope/yepnope.1.5.4-min.js', | |
'./js-src/yepnope-loader.js'] | |
}; | |
var paths_dest = { | |
compass: '.', | |
svgmin: './img', | |
svg2png: './img', | |
uglify: './js', | |
headerimages: './img/header-image', | |
portfolio: './img/portfolio' | |
}; | |
// Compass | |
gulp.task('compass', function() { | |
gulp.src(paths_src.compass) | |
.pipe(plugins.plumber({errorHandler: plugins.notify.onError("Error: <%= error.message %>")})) | |
.pipe(plugins.compass({ | |
config_file: './config.rb', | |
css: '.', | |
sass: 'sass', | |
image: 'img', | |
font: 'fonts' | |
})) | |
.pipe(plugins.autoprefixer("last 2 versions", "> 1%", "ie 8")) | |
.pipe(gulp.dest(paths_dest.compass)) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Sass complete' })) | |
}); | |
// SVG optim | |
gulp.task('svgmin', function() { | |
gulp.src(paths_src.svgmin) | |
.pipe(plugins.svgmin()) | |
.pipe(gulp.dest(paths_dest.svgmin)) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Svgoptim complete' })) | |
}); | |
// SVG 2 png | |
gulp.task('svg2png', function () { | |
gulp.src(paths_src.svg2png) | |
.pipe(plugins.svg2png()) | |
.pipe(gulp.dest(paths_dest.svg2png)) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Svg2png complete' })) | |
}); | |
// Uglify | |
gulp.task('uglify', function() { | |
gulp.src(paths_src.uglify) | |
.pipe(plugins.plumber({errorHandler: plugins.notify.onError("Error: <%= error.message %>")})) | |
.pipe(plugins.concat('functions-13051541.min.js')) | |
.pipe(plugins.stripDebug()) | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest(paths_dest.uglify)) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Uglify complete' })); | |
gulp.src(paths_src.yepnope) | |
.pipe(plugins.plumber({errorHandler: plugins.notify.onError("Error: <%= error.message %>")})) | |
.pipe(plugins.concat('yepnope-13051541.min.js')) | |
.pipe(plugins.stripDebug()) | |
.pipe(plugins.uglify()) | |
.pipe(gulp.dest(paths_dest.uglify)) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Uglify complete' })); | |
}); | |
// Create all responsive images | |
gulp.task('rename', function () { | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 480, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-mobile"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 768, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-skinny"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 992, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-medium"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 1280, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-desktop"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 1430, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-wide"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 1600, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-widescreen"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
gulp.src('./img-src/header-image/*.jpg') | |
.pipe(plugins.imageResize({ width: 1920, quality: .8, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-ultra"; })) | |
.pipe(gulp.dest('./img/header-image')) | |
.pipe(plugins.notify({ message: 'Headerimages complete' })) | |
}); | |
// Portfolio images | |
gulp.task('portfolio', function () { | |
gulp.src('./img-src/portfolio/*.png') | |
.pipe(plugins.imageResize({ width: 480, quality: 1, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-mobile"; })) | |
.pipe(gulp.dest('./img/portfolio')) | |
gulp.src('./img-src/portfolio/*.png') | |
.pipe(plugins.imageResize({ width: 768, quality: 1, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-skinny"; })) | |
.pipe(gulp.dest('./img/portfolio')) | |
gulp.src('./img-src/portfolio/*.png') | |
.pipe(plugins.imageResize({ width: 992, quality: 1, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-medium"; })) | |
.pipe(gulp.dest('./img/portfolio')) | |
gulp.src('./img-src/portfolio/*.png') | |
.pipe(plugins.imageResize({ width: 1265, quality: 1, imageMagick: true })) | |
.pipe(plugins.rename(function (path) { path.basename += "-desktop"; })) | |
.pipe(gulp.dest('./img/portfolio')) | |
.pipe(plugins.notify({ message: 'Portfolio complete' })) | |
}); | |
// SVG sprites optim | |
gulp.task('svgspritesoptim', function() { | |
gulp.src('./img-src/sprites/**/*.svg') | |
.pipe(plugins.svgmin()) | |
.pipe(gulp.dest('./img/sprites')) | |
.pipe(plugins.livereload(server)) | |
.pipe(plugins.notify({ message: 'Svg sprites optim complete' })) | |
}); | |
// SVG sprites | |
var svg = plugins.svgSprites.svg; | |
var png = plugins.svgSprites.png; | |
gulp.task('sprites', function () { | |
//return gulp.src('./img/sprites/*.svg') | |
return gulp.src(['./img/sprites/general/*.svg', | |
'./img/sprites/icons/*.svg', | |
'./img/sprites/socials/*.svg', | |
'./img/sprites/clients/*.svg', | |
'./img/sprites/repeaters/*.svg']) | |
.pipe(svg({padding: 10, | |
cssFile: '../sass/sprites/_sprites.scss', | |
svgPath: 'img/%f', | |
pngPath: 'img/%f', | |
generatePreview: false | |
})) | |
.pipe(gulp.dest('./img')) | |
.pipe(png()) | |
.pipe(plugins.notify({ message: 'Svg sprites optim complete' })) | |
}); | |
// SCSS lint | |
gulp.task('lint', function() { | |
gulp.src('./sass/**/*.scss') | |
.pipe(plugins.scsslint()) | |
.pipe(plugins.scsslint.reporter()) | |
.pipe(plugins.notify({ message: 'SCSS lint complete' })) | |
}); | |
// Watch | |
gulp.task('watch', function() { | |
server.listen(35729, function(err) { | |
gulp.watch(paths_src.compass, ['compass']); | |
gulp.watch([paths_src.uglify, paths_src.yepnope], ['uglify']); | |
gulp.watch(paths_src.svgmin, ['svgmin']); | |
gulp.watch(paths_src.svg2png, ['svg2png']); | |
}) | |
}); | |
// Default | |
gulp.task('default', ['watch']); | |
gulp.task('svgsprites', ['svgspritesoptim', 'sprites']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment