website_template/gulpfile.js

87 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-07-29 02:50:38 +02:00
// Require all those npm-modules
2014-06-29 12:46:19 +02:00
2015-07-27 09:49:42 +02:00
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssmin = require('gulp-cssmin'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
pngcrush = require('imagemin-pngcrush'),
rename = require('gulp-rename'),
del = require('del'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
plumber = require('gulp-plumber');
2014-06-29 12:46:19 +02:00
2014-07-29 02:50:38 +02:00
// render scss
2015-07-27 09:49:42 +02:00
gulp.task('styles', function() {var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Submarine"
})(err);
this.emit('end');
};
2015-07-27 12:25:14 +02:00
gulp.src('./src/scss/main.scss')
2015-07-27 09:49:42 +02:00
.pipe(plumber({errorHandler: onError}))
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'IE 9', 'safari 5', 'Firefox ESR', 'opera 12.1', 'ios 6', 'android 4', 'BlackBerry 10'))
.pipe(gulp.dest('./css'))
.pipe(rename({suffix: '.min'}))
.pipe(cssmin())
.pipe(gulp.dest('./css'))
.pipe(notify({ message: 'Styles task complete' }));
2014-07-29 02:50:38 +02:00
});
2014-06-29 12:46:19 +02:00
2015-07-27 09:49:42 +02:00
2014-07-29 02:50:38 +02:00
// compress images
gulp.task('images', function() {
2015-07-27 09:49:42 +02:00
gulp.src('./src/img/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('./img/'))
.pipe(notify({ message: 'Images task complete' }));
2014-07-29 02:50:38 +02:00
});
// do the javascript-dance
gulp.task('scripts', function() {
2015-07-27 09:49:42 +02:00
gulp.src('./src/js/**/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('./js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./js'))
.pipe(notify({ message: 'Scripts task complete' }));
2014-07-29 02:50:38 +02:00
});
2015-07-27 09:49:42 +02:00
2014-07-29 14:49:08 +02:00
// watch it while working
2014-07-29 02:50:38 +02:00
gulp.task('watch', function() {
2015-07-27 09:49:42 +02:00
// Watch .scss files
gulp.watch('src/scss/**/*.scss', ['styles']);
2014-07-29 02:50:38 +02:00
2015-07-27 09:49:42 +02:00
// Watch .js files
gulp.watch('src/js/**/*.js', ['scripts']);
2014-07-29 02:50:38 +02:00
2015-07-27 09:49:42 +02:00
// Watch image files
gulp.watch('src/img/**/*', ['images']);
2014-07-29 02:50:38 +02:00
});
2015-07-27 09:49:42 +02:00
// clean the folders
gulp.task('clean', function(cb) {
del(['./css/*', './js/*', './img/*'], cb)
});
2014-07-29 14:49:08 +02:00
// default: all of them! \o/
2014-07-29 02:50:38 +02:00
gulp.task('default', ['clean'], function() {
2015-07-27 09:49:42 +02:00
gulp.start('styles', 'scripts', 'images');
2014-06-29 12:46:19 +02:00
});