Skip to content

Instantly share code, notes, and snippets.

@risyasin
Created May 19, 2015 21:50
Show Gist options
  • Save risyasin/86a9d3f82f79d90cbb9a to your computer and use it in GitHub Desktop.
Save risyasin/86a9d3f82f79d90cbb9a to your computer and use it in GitHub Desktop.
Gulp config with jshint, css/js minify, concat, livereload/browsersync, nodemon
"use strict";
var gulp = require('gulp'),
concat = require('gulp-concat'),
nodemon = require('gulp-nodemon'),
mincss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
head = require('gulp-header'),
bs = require('browser-sync').create(),
cfg = require('./config.js'),
date = new Date().toLocaleString(),
src = {};
/* ---------------------------------- */
src.css = {
'files': [
'public/css/bootstrap.css',
'public/css/app.css'
],
'dest': 'public/css/',
'name': 'all.min.css'
};
src.js = {
'files': [
'public/js/jquery-2.1.3.js',
'public/js/bootstrap.js',
'public/js/masonry.pkgd.js',
'public/js/app.js'
],
'dest': 'public/js/',
'name': 'all.min.js'
};
src.app = {
'main': 'index.js',
'files': [
'lib.js',
'config.js',
'gulpfile.js',
'libs/*.js'
],
'ignore': [
'.idea/*',
'node_modules/*',
'public/*'
]
};
/* ---------------------------------- */
src.css.files.push('!'+src.css.dest+src.css.name);
src.js.files.push('!'+src.js.dest+src.js.name);
src.app.files.push(src.app.main);
gulp.task('css', function () {
return gulp.src(src.css.files)
.pipe(mincss())
.pipe(concat(src.css.name))
.pipe(head('/* created at '+date+' */'+'\r\n'))
.pipe(gulp.dest(src.css.dest));
});
gulp.task('js', function () {
return gulp.src(src.js.files)
.pipe(concat(src.js.name))
.pipe(head('/* created at '+date+' */'+'\r\n'))
.pipe(gulp.dest(src.js.dest));
});
gulp.task('js-uglify', function () {
return gulp.src(src.js.files)
.pipe(uglify())
.pipe(concat(src.js.name))
.pipe(head('/* created at '+date+' */'+'\r\n'))
.pipe(gulp.dest(src.js.dest));
});
gulp.task('lint', function () {
return gulp.src(src.app.files)
.pipe(jshint())
.pipe(jshint.reporter('default', { verbose: true }));
});
gulp.task('reload-css', ['css'], function () {
bs.reload();
});
gulp.task('reload-js', ['js'], function () {
bs.reload();
});
gulp.task('watch', ['css', 'js'], function () {
gulp.watch(src.css.files, ['reload-css']);
gulp.watch(src.js.files, ['reload-js']);
});
gulp.task('default', ['watch'], function() {
nodemon({
'script': 'index.js',
'ext': 'jade js',
'ignore': src.app.ignore
}).on('start', function () {
setTimeout(function () {
if (typeof src.app.bs === 'undefined'){
src.app.bs = bs.init({proxy: "localhost:"+cfg.port});
} else {
bs.reload();
}
}, 1000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment