Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
imagehover.css/gulpfile.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
100 lines (92 sloc)
2.06 KB
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
/** | |
* Load modules | |
*/ | |
const gulp = require('gulp'); | |
const cssnano = require('gulp-cssnano'); | |
const notify = require('gulp-notify'); | |
const plumber = require('gulp-plumber'); | |
const rename = require('gulp-rename'); | |
const sass = require('gulp-sass'); | |
const sourcemaps = require('gulp-sourcemaps'); | |
const autoprefixer = require('autoprefixer'); | |
const postcss = require('gulp-postcss'); | |
const clean = require('gulp-clean'); | |
/** | |
* Custom error function for Plumber. | |
* | |
* @param err | |
*/ | |
const onError = function(err) { | |
notify.onError({ | |
title: "Error", | |
message: "<%= error %>", | |
})(err); | |
this.emit('end'); | |
}; | |
/** | |
* Plumber options | |
* | |
* @type {{errorHandler: onError}} | |
*/ | |
const plumberOptions = { | |
errorHandler: onError, | |
}; | |
/** | |
* Gulp minify task | |
* | |
* Build and minify styles for production/distributed use. | |
*/ | |
gulp.task('minify', () => { | |
return gulp.src('./css/imagehover.css') | |
.pipe(cssnano()) | |
.pipe(rename('imagehover.min.css')) | |
.pipe(gulp.dest('./css')); | |
}); | |
/** | |
* Build task | |
*/ | |
gulp.task('build', () => { | |
return gulp.src('scss/imagehover.scss') | |
.pipe(plumber(plumberOptions)) | |
.pipe(sourcemaps.init()) | |
.pipe(sass({ | |
indentWidth: 4, | |
outputStyle: 'expanded', | |
})) | |
.pipe(sourcemaps.write('/')) | |
.pipe(gulp.dest('css')); | |
}); | |
/** | |
* Clean dist directory | |
*/ | |
gulp.task('clean', () => { | |
return gulp.src('./css/imagehover*.css*', {read: false}) | |
.pipe(clean({force: true})); | |
}); | |
/** | |
* Auto prefix CSS | |
*/ | |
gulp.task('autoprefixer', () => { | |
return gulp.src('./css/imagehover.css') | |
.pipe(sourcemaps.init()) | |
.pipe(postcss([ autoprefixer() ])) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('./css/')); | |
}); | |
/** | |
* Gulp watch task | |
*/ | |
gulp.task('watch', () => { | |
// Watch SCSS files for changes | |
return gulp.watch( | |
['scss/**/*.scss'], | |
gulp.series('default') | |
); | |
}); | |
/** | |
* Default Gulp task | |
* | |
* Build then watch SCSS files. | |
* | |
*/ | |
gulp.task('default', gulp.series('clean', 'build', 'autoprefixer', 'minify')); |