Skip to content

Instantly share code, notes, and snippets.

@msrafi
Forked from samuelhorn/gulpfile.js
Last active August 29, 2015 14:17
Show Gist options
  • Save msrafi/7941a7bf813b99832874 to your computer and use it in GitHub Desktop.
Save msrafi/7941a7bf813b99832874 to your computer and use it in GitHub Desktop.
/*******************************************************************************
1. DEPENDENCIES
*******************************************************************************/
var gulp = require('gulp'); // gulp core
sass = require('gulp-sass'), // sass compiler
uglify = require('gulp-uglify'), // uglifies the js
// jshint = require('gulp-jshint'), // check if js is ok
rename = require("gulp-rename"); // rename files
concat = require('gulp-concat'), // concatinate js
notify = require('gulp-notify'), // send notifications to osx
plumber = require('gulp-plumber'), // disable interuption
stylish = require('jshint-stylish'), // make errors look good in shell
minifycss = require('gulp-minify-css'), // minify the css files
browserSync = require('browser-sync'), // inject code to all devices
autoprefixer = require('gulp-autoprefixer'); // sets missing browserprefixes
/*******************************************************************************
2. FILE DESTINATIONS (RELATIVE TO ASSSETS FOLDER)
*******************************************************************************/
var target = {
sass_src : 'dev/assets/css/*.scss', // all sass files
css_dest : 'dev/assets/css/', // where to put minified css
js_lint_src : [ // all js that should be linted
'dev/assets/js/hsiarch.js'
],
js_uglify_src : [ // all js files that should not be concatinated
],
js_concat_src : [ // all js files that should be concatinated
'dev/assets/js/jquery.js',
'dev/assets/js/slick.js',
'dev/assets/js/jquery.hoverIntent.minified.js',
'dev/assets/js/hsiarch.js'
],
js_dest : 'dev/assets/js/' // where to put minified js
};
/*******************************************************************************
3. SASS TASK
*******************************************************************************/
gulp.task('sass', function() {
gulp.src(target.sass_src) // get the files
.pipe(plumber()) // make sure gulp keeps running on errors
.pipe(sass()) // compile all sass
.pipe(minifycss()) // minify css
.pipe(gulp.dest(target.css_dest)) // where to put the file
.pipe(notify({message: 'SCSS processed!'})); // notify when done
});
/*******************************************************************************
4. JS TASKS
*******************************************************************************/
// lint my custom js
// gulp.task('js-lint', function() {
// gulp.src(target.js_lint_src) // get the files
// .pipe(jshint()) // lint the files
// .pipe(jshint.reporter(stylish)) // present the results in a beautiful way
// });
// minify all js files that should not be concatinated
gulp.task('js-uglify', function() {
gulp.src(target.js_uglify_src) // get the files
.pipe(uglify()) // uglify the files
.pipe(rename(function(dir,base,ext){ // give the files a min suffix
var trunc = base.split('.')[0];
return trunc + '.min' + ext;
}))
.pipe(gulp.dest(target.js_dest)) // where to put the files
.pipe(notify({ message: 'JS processed!'})); // notify when done
});
// minify & concatinate all other js
gulp.task('js-concat', function() {
gulp.src(target.js_concat_src) // get the files
.pipe(uglify()) // uglify the files
.pipe(concat('hsiarch.min.js')) // concatinate to one file
.pipe(gulp.dest(target.js_dest)) // where to put the files
.pipe(notify({message: 'JS processed!'})); // notify when done
});
/*******************************************************************************
5. BROWSER SYNC
*******************************************************************************/
gulp.task('browser-sync', function() {
browserSync.init(['dev/assets/css/*.css', 'dev/assets/js/*.js'], { // files to inject
proxy: {
host: 'localhost', // development server
port: '2368' // development server port
}
});
});
/*******************************************************************************
1. GULP TASKS
*******************************************************************************/
gulp.task('default', ['sass', 'js-uglify', 'js-concat'], function() {
gulp.run('sass', 'js-uglify', 'js-concat', 'browser-sync');
gulp.watch('scss/**/*.scss', function() {
gulp.run('sass');
});
// gulp.watch(target.js_lint_src, function() {
// gulp.run('js-lint');
// });
gulp.watch(target.js_minify_src, function() {
gulp.run('js-uglify');
});
gulp.watch(target.js_concat_src, function() {
gulp.run('js-concat');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment