Guest User

Gulp

a guest
Jul 14th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var gulp = require('gulp'),
  2.     sass = require('gulp-sass'),
  3.     autoprefixer = require('gulp-autoprefixer'),
  4.     minifycss = require('gulp-minify-css'),
  5.     path = 'style',
  6.     imgpath = 'img',
  7.     plumber = require('gulp-plumber'),
  8.     browserSync = require('browser-sync').create(),
  9.     jshint = require('gulp-jshint'),
  10.     rename = require('gulp-rename'),
  11.     notify = require("gulp-notify"),
  12.     cssBase64 = require('gulp-css-base64'),
  13.     imageop = require('gulp-image-optimization');
  14.  
  15. function ScssErrorAlert(error){
  16.     notify.onError({title: "SCSS Error", message: error.toString(), sound: "Sosumi"})(error); //Error Notification
  17.     console.log(error.toString());//Prints Error to Console
  18.     this.emit("end"); //End function
  19. };
  20.  
  21. gulp.task('images', function(cb) {
  22.     gulp.src([imgpath+'/**/*.png','src/**/*.jpg','src/**/*.gif','src/**/*.jpeg']).pipe(imageop({
  23.         optimizationLevel: 5,
  24.         progressive: true,
  25.         interlaced: true
  26.     })).pipe(gulp.dest('public/images')).on('end', cb).on('error', cb);
  27. });
  28.  
  29. gulp.task('styles', function() {
  30.   return gulp.src(path+'/*.scss')
  31.     // .pipe(plumber({
  32.    //      errorHandler: function (err) {
  33.    //          console.log(err);
  34.    //          this.emit('end');
  35.    //      }}))
  36.     .pipe(plumber({errorHandler: ScssErrorAlert}))
  37.     .pipe(sass({ style: 'expanded' }))
  38.     .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
  39.     .pipe(gulp.dest(path))
  40.     .pipe(rename({suffix: '.min'}))
  41.     .pipe(minifycss())
  42.     .pipe(gulp.dest(path))
  43.     .pipe(browserSync.stream())
  44. });
  45.  
  46.  
  47.  
  48. gulp.task('watch', function() {
  49.     gulp.watch(path+'/**/*.scss', ['styles']);
  50.     gulp.watch(path+'/*.scss', ['styles']);
  51.     gulp.watch('js/**/*.js', ['jshint']);
  52.  
  53. });
  54.  
  55. gulp.task('jshint', function() {
  56.     return gulp.src('js/main.js')
  57.     .pipe(jshint())
  58.     .pipe(jshint.reporter('jshint-stylish'));
  59.  
  60. });
  61.  
  62.  
  63.  
  64. // Favicon
  65. // sprite
  66. gulp.task('browser-sync', function() {
  67.     browserSync.init({
  68.         proxy: "adrian.dev"
  69.     });
  70.     gulp.watch(path+"/*.scss", ['styles']);
  71.     gulp.watch(path+'/**/*.scss', ['styles']);
  72.     gulp.watch("*.html").on('change', browserSync.reload);
  73.     gulp.watch("js/*.js").on('change', browserSync.reload);
  74. });
  75.  
  76. gulp.task('encode', function () {
  77.     return gulp.src(path+'/main.min.css')
  78.         .pipe(cssBase64())
  79.         .pipe(gulp.dest(path));
  80. });
  81.  
  82. gulp.task('default', ['watch', 'browser-sync', 'encode'], function() {
  83.  
  84. });
Advertisement
Add Comment
Please, Sign In to add comment