2016-10-04 15:02:31 +00:00
|
|
|
// gulpfile.js
|
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Dependencies =================================
|
|
|
|
* | uses/functions of each are provided indiviudally.
|
|
|
|
*/
|
2016-10-04 15:02:31 +00:00
|
|
|
var gulp = require('gulp'), // task runner/manager (even tho this is a small project, it's still nice to have)
|
|
|
|
sass = require('gulp-sass'), // compiles sass for us
|
|
|
|
notify = require('gulp-notify'), // notifies us when a gulp task is completed through a system notifcation
|
|
|
|
rename = require('gulp-rename'), // allows us to rename files (adding prefixes and suffixes is the main use here).
|
|
|
|
autoprefixer = require('gulp-autoprefixer'), // great for catching those annoying vendor prefixes on css attributets and values.
|
2016-10-04 20:10:25 +00:00
|
|
|
minify = require('gulp-cssnano'), // minify our compiled css. sass can do this natively (kind of), so this is used in conjunction with gulp-sass.
|
2016-10-04 15:02:31 +00:00
|
|
|
del = require('del'); // del is used to cleanup cache and build files.
|
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Variables ====================================
|
|
|
|
* | silly, long, reused paths/dirs go here if needed.
|
|
|
|
*/
|
2016-10-04 18:36:54 +00:00
|
|
|
var $supported = [
|
|
|
|
'last 2 versions',
|
|
|
|
'safari >= 8',
|
|
|
|
'ie >= 10',
|
|
|
|
'ff >= 20',
|
|
|
|
'ios 6',
|
|
|
|
'android 4'
|
|
|
|
];
|
2016-10-04 16:44:17 +00:00
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Gulp Tasks ===================================
|
|
|
|
* | All gulp tasks will be written/explained here.
|
|
|
|
*/
|
2016-10-04 15:02:31 +00:00
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Build CSS Task -------------------------------
|
|
|
|
* | $ gulp build
|
|
|
|
* |
|
2016-10-04 18:36:54 +00:00
|
|
|
* | 1. compiles scss into css,
|
|
|
|
* | 2. autoprefix necessary css attributes/values,
|
|
|
|
* | 3. place compiled file into ./css directory
|
|
|
|
* | 4. minify prefixed css,
|
|
|
|
* | 5. rename minified file with a '.min' suffix,
|
|
|
|
* | 6. place minified file into ./css directory
|
|
|
|
* | 7. notify on task completion
|
2016-10-04 17:03:59 +00:00
|
|
|
*/
|
2016-10-04 16:44:17 +00:00
|
|
|
gulp.task('build', function() {
|
|
|
|
return gulp.src('./sass/**/*.scss')
|
2016-10-04 18:36:54 +00:00
|
|
|
.pipe(sass({ // 1.
|
|
|
|
outputStyle: 'expanded'
|
|
|
|
}).on('error', sass.logError))
|
|
|
|
.pipe(autoprefixer({ // 2.
|
|
|
|
browsers: $supported,
|
|
|
|
add: true,
|
|
|
|
cascade: false
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./css')) // 3.
|
|
|
|
.pipe(minify({ // 4.
|
|
|
|
discardUnused: { fontFace: false }
|
|
|
|
}))
|
|
|
|
.pipe(rename({ // 5.
|
|
|
|
suffix: '.min'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./css')) // 6.
|
|
|
|
.pipe(notify({ // 7.
|
|
|
|
onLast: true,
|
|
|
|
message: 'build task complete!'
|
|
|
|
}));
|
2016-10-04 16:44:17 +00:00
|
|
|
});
|
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Clean Task -----------------------------------
|
|
|
|
* | $ gulp clean
|
|
|
|
* |
|
|
|
|
* | Ensures that all artifacts/remnants of previous build are gone.
|
|
|
|
*/
|
2016-10-04 16:44:17 +00:00
|
|
|
gulp.task('clean', function() {
|
|
|
|
return del(['./css/**/*.*']);
|
|
|
|
});
|
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Watch Task -----------------------------------
|
|
|
|
* | $ gulp watch
|
|
|
|
* |
|
|
|
|
* | Great for automating compilation during develpoment.
|
|
|
|
*/
|
2016-10-04 16:44:17 +00:00
|
|
|
gulp.task('watch', function() {
|
|
|
|
gulp.watch('./sass/**/*.scss', ['clean', 'build']);
|
|
|
|
});
|
|
|
|
|
2016-10-04 17:03:59 +00:00
|
|
|
/*
|
|
|
|
* Default Task ---------------------------------
|
|
|
|
* | $ gulp
|
|
|
|
* | $ gulp default
|
|
|
|
* |
|
|
|
|
* | Runs the watch task as a task dependency by default.
|
|
|
|
*/
|
2016-10-04 16:44:17 +00:00
|
|
|
gulp.task('default', ['watch']);
|