Created
July 6, 2017 15:27
-
-
Save ivanmrchk/0253f651a34627c2142b62eea971b847 to your computer and use it in GitHub Desktop.
General every day use gulp file
This file contains hidden or 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'); | |
var uglify = require('gulp-uglify'); | |
var sass = require('gulp-ruby-sass'); | |
var livereload = require('gulp-livereload'); | |
var imagemin = require('gulp-imagemin'); | |
var prefix = require('gulp-autoprefixer'); | |
function errorLog(error) { | |
console.error.bind(error); | |
this.emit('end'); | |
} | |
// minimize js | |
gulp.task('scripts', function(){ | |
gulp.src('js/*.js') | |
.pipe(uglify()) | |
.on('error', errorLog) | |
.pipe(gulp.dest('build/js')) | |
}); | |
// Watch Task | |
gulp.task('watch', function(){ | |
livereload.listen(); | |
gulp.watch('js/*.js', ['scripts']); | |
gulp.watch('scss/**/*.scss', ['styles']); | |
gulp.watch('./*.html', ['html']) | |
}); | |
// html reload | |
gulp.task('html', function(){ | |
gulp.src('./*.html') | |
.pipe(livereload()) | |
}); | |
// sass compile, reload and prefix css | |
gulp.task('styles', function(){ | |
return sass('scss/**/*.scss', {style: 'compressed'}) | |
.on('error', errorLog) | |
.pipe(prefix('last 2 versions')) | |
.pipe(gulp.dest('css/')) | |
.pipe(livereload()) | |
}); | |
// compress images (not part of default task) | |
gulp.task('image', function(){ | |
gulp.src('img/**/*') | |
.pipe(imagemin()) | |
.pipe(gulp.dest('build/img')); | |
}) | |
gulp.task('default', [ 'styles', 'html', 'watch' ]); | |
// kill -9 $(lsof -t -i :35729) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment