hacks-guide-minimal-mistake.../gulpfile.js

98 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-03-08 04:20:32 +01:00
/* ==========================================================================
MINIMAL MISTAKES JEKYLL THEME - Gulpfile
========================================================================== */
/**
*
* Packages used
*
**/
2016-03-18 15:54:47 +01:00
var gulp = require('gulp');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglifyjs');
var jshint = require('gulp-jshint');
var rename = require('gulp-rename');
var imagemin = require('gulp-imagemin');
var imageminMozjpeg = require('imagemin-mozjpeg');
2016-03-08 04:20:32 +01:00
/**
*
* Styles
* - Compile
* - Compress/Minify
* - Catch errors (gulp-plumber)
* - Run through Autoprefixer
*
**/
2016-03-18 15:44:09 +01:00
gulp.task('css', function() {
return gulp.src('assets/_scss/**/*.scss')
2016-03-18 15:44:09 +01:00
.pipe(sass({outputStyle: 'compressed'}))
.pipe(prefix('last 2 versions', '> 5%', 'ie 9'))
2016-03-09 18:10:43 +01:00
.pipe(plumber())
2016-03-18 15:44:09 +01:00
.pipe(gulp.dest('assets/css'));
2016-03-08 04:20:32 +01:00
});
/**
*
* Javascript
* - Concatenate main script with plugins
* - Uglify
* - Rename
*
**/
2016-03-18 15:44:09 +01:00
gulp.task('scripts', function() {
return gulp.src(['assets/js/vendor/jquery/*.js', 'assets/js/plugins/**/*.js', 'assets/js/_main*.js'])
2016-03-08 04:20:32 +01:00
.pipe(uglify())
.pipe(rename({
2016-03-18 15:44:09 +01:00
basename: 'main',
suffix: '.min',
2016-03-08 04:20:32 +01:00
}))
2016-03-18 15:44:09 +01:00
.pipe(gulp.dest('assets/js'))
2016-03-08 04:20:32 +01:00
});
/**
*
* Javascript
* - Lint for errors
*
**/
2016-03-18 15:44:09 +01:00
gulp.task('jslint', function() {
return gulp.src('assets/js/_*.js')
2016-03-08 04:20:32 +01:00
.pipe(jshint())
2016-03-18 15:44:09 +01:00
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
2016-03-08 04:20:32 +01:00
});
/**
*
* Images
* - Optimize image assets
*
**/
2016-03-18 15:44:09 +01:00
gulp.task('images', function () {
return gulp.src('images/*')
2016-03-09 18:10:43 +01:00
.pipe(imagemin({
// optimizationLevel: 7,
2016-03-09 18:10:43 +01:00
progressive: true,
2016-03-18 15:54:47 +01:00
interlaced: true,
svgoPlugins: [{removeViewBox: true}],
// use: [imageminMozjpeg()]
2016-03-09 18:10:43 +01:00
}))
2016-03-18 15:44:09 +01:00
.pipe(gulp.dest('images'));
2016-03-08 04:20:32 +01:00
});
/**
*
* Default task
* - Runs scss, scripts, and image tasks
* - Watches for scss and script changes
2016-03-08 04:20:32 +01:00
*
**/
2016-03-20 03:00:55 +01:00
gulp.task('default', ['css', 'jslint', 'images', 'scripts'], function () {
2016-03-19 01:53:56 +01:00
gulp.watch('assets/_scss/**/*.scss', ['css']);
2016-03-18 15:44:09 +01:00
gulp.watch('assets/js/_*.js', ['jslint']);
gulp.watch(['!assets/js/**/*_.js', 'assets/js/plugins/**/*.js', 'assets/js/vendor/**/*.js'], ['scripts']);
2016-03-08 04:20:32 +01:00
});