Giter Club home page Giter Club logo

gulpfile's Introduction

👹 Gulpfile

⚠️ legacy code 🤷

A simple gulpfile with some utils, ready to be shared across different projects

How to install and use gulp.js

please refer to gulp installation

Gulp Installation Guide

What you get

In this gulpfile you'll find

  • SASS
    • Compile and watch tasks
    • Autoprefixer
    • Sourcemaps
    • Media query combination and optimization
    • Minification and concatenation
    • DEV and PROD version
  • JS
    • Compile and watch tasks
    • Minification and concatenation
    • DEV and PROD version
  • Images
    • Optimization and conversion
  • BrowserSync
  // include gulp
  var gulp = require('gulp');
  
  // include plug-ins
  // SASS and SASS Utils
  var sass = require('gulp-sass');
  var sourcemaps = require('gulp-sourcemaps');
  var autoprefix = require('gulp-autoprefixer');
  var minifyCSS = require('gulp-minify-css');
  var concat = require('gulp-concat');
  var stripDebug = require('gulp-strip-debug');
  var uglify = require('gulp-uglify');
  var combineMq = require('gulp-combine-mq');
  // Image optimization
  var imagemin = require('gulp-imagemin');
  var imageop = require('gulp-image-optimization');
  // Utils
  var print = require('gulp-print');
  var count = require('gulp-count');
  var browserSync = require('browser-sync').create();
  
  'use strict';
  // browserSync task
  gulp.task('browser-sync', function() {
      browserSync.init({
          proxy: "localhost:8888/"
      });
  });
  
  
  gulp.task('images', function(cb) {
      gulp.src(['./images/**/*.png','./images/**/*.jpg','./images/**/*.gif','./images/**/*.jpeg']).pipe(imageop({
          optimizationLevel: 10,
          progressive: true,
          interlaced: true
      })).pipe(gulp.dest('./images-opt')).on('end', cb).on('error', cb);
  });
  
  gulp.task('sass', function () {
      gulp.src('./scss/**/*.scss')
          .pipe(sourcemaps.init())
          .pipe(sass().on('error', sass.logError))
          .pipe(autoprefix('last 10 versions'))
          .pipe(sourcemaps.write('./maps'))
          .pipe(gulp.dest('./css'))
  });
  
  
  gulp.task('combineMq', function () {
      return gulp.src('./css/style.css')
          .pipe(combineMq({
              beautify: false
          }))
          .pipe(minifyCSS())
          .pipe(gulp.dest('./css/'));
  });
  
  
  gulp.task('minifyCSS', function() {
      return gulp.src('./css/style.css')
          .pipe(combineMq({
              beautify: false
          }))
          .pipe(minifyCSS())
          .pipe(gulp.dest('./css/prod/'))
  });
  
  gulp.task('sass:watch', function () {
      gulp.watch('./scss/**/*.scss', ['sass']);
  });
  
  gulp.task('sass:watch:minify', function () {
      gulp.watch('./css/style.css', ['minifyCSS']);
  });
  
  gulp.task('compressJs', function() {
      return gulp.src('./js/**/*.js')
      // .pipe(concat('main.min.js'))
          .pipe(uglify({
              mangle:false
          }))
          .pipe(gulp.dest('./js/prod/'));
  });
  
  gulp.task('createProdJS', function () {
      var paths = [
          //List below all the js you want to include in the prod version
          'js/vendor/jquery.min.js',
          'js/main.js'
      ];
      console.log('Following files and dirs will be included (Total %s): ', paths.length);
      return gulp.src(paths, {base: './js'})
          .pipe(count('## assets selected'))
          .pipe(print())
          .pipe(concat('main.min.js'))
          .pipe(uglify({
              mangle:false
          }))
          .pipe(gulp.dest('./js/minified/'));
  
  });
  
  gulp.task('createProdCSS', function () {
      var paths = [
          //List below all the css you want to include in the prod version
          // 'bootstrap/dist/css/bootstrap-theme.css',
          // 'bootstrap/dist/css/bootstrap.css',
          // 'css/style.css'
      ];
      // console.log('Following files and dirs will be included (Total %s): ', paths.length);
      return gulp.src(paths, {base: './css'})
          // .pipe(count('## assets selected'))
          // .pipe(print())
          .pipe(concat('style.min.css'))
          .pipe(minifyCSS())
          .pipe(gulp.dest('./css/'));
  
  });
  
  gulp.task('scripts:watch:compress', function () {
      gulp.watch('./js/main.js', ['compressJs']);
  });
  
  
  // JS concat, strip debugging and minify
  gulp.task('processJs', function() {
      return gulp.src('./js/**/*.js')
          .pipe(concat('main.min.js'))
          .pipe(uglify({
              mangle:false
          }))
          .pipe(gulp.dest('./js/min/'));
  });
  
  gulp.task('default', [
          'sass',
          'minifyCSS',
          'compressJs',
          'sass:watch',
          'scripts:watch',
          'scripts:watch:compress',
          'sass:watch:minify'
      ]
  );
  // decomment the line below to activate gulp extension in chrome inspector
  // module.exports = gulp;

gulpfile's People

Contributors

federico-villani avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.