Skip to content

Instantly share code, notes, and snippets.

@michaeljymsgutierrez
Created July 30, 2018 00:29
Show Gist options
  • Select an option

  • Save michaeljymsgutierrez/fc1006e93a0a2308b6a322275854e2fb to your computer and use it in GitHub Desktop.

Select an option

Save michaeljymsgutierrez/fc1006e93a0a2308b6a322275854e2fb to your computer and use it in GitHub Desktop.
Set of gulp useful tasks
var gulp = require('gulp');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var pump = require('pump');
var uglify = require('gulp-uglify');
var webserver = require('gulp-webserver');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var paths = {
sass: ['./scss/*.scss', 'template/**/*.scss']
};
gulp.task('default', ['sass']);
/* Compile SASS */
gulp.task('sass', function(done) {
gulp.src('./scss/orrasu.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('./css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./css/'))
.on('end', done);
});
/* Watch Mode */
gulp.task('watch', ['sass'], function() {
gulp.watch(paths.sass, ['sass']);
});
/* Prepare Main JS */
gulp.task('prepare-main-js', function() {
gulp.src(['./js/*.js', './template/**/*.js'])
.pipe(uglify())
.pipe(gulp.dest('build/prepare'))
});
/* Build Main JS */
gulp.task('build-main-js', function() {
setTimeout(function() {
gulp.src(['./build/prepare/**/*.js'])
.pipe(concat('main.js'))
.pipe(gulp.dest('build'))
}, 3000);
});
/* Buil Main JS for Prod */
gulp.task('build-prod-js', ['build-main-js', 'prepare-main-js']);
/* Minify all js */
gulp.task('compress', function() {
pump([gulp.src(['js/*.js', 'template/**/*.js']),
uglify(),
gulp.dest('prod')
]);
});
/* Live Reload */
gulp.task('serve', function() {
gulp.src(__dirname)
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true
}));
});
/* Custom Linter */
gulp.task('lint', function() {
return gulp.src(['js/*.js', 'template/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish', { verbose: true }));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment