Last active
August 29, 2015 14:15
-
-
Save boynoiz/fbabb5b3367f8537779d to your computer and use it in GitHub Desktop.
My Gulpfile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* gulp | |
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-minify-css gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del gulp-sourcemaps --save-dev | |
*/ | |
// Load plugins | |
var gulp = require('gulp'), | |
sass = require('gulp-ruby-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
minifyCSS = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
uglify = require('gulp-uglify'), | |
imagemin = require('gulp-imagemin'), | |
rename = require('gulp-rename'), | |
concat = require('gulp-concat'), | |
notify = require('gulp-notify'), | |
cache = require('gulp-cache'), | |
livereload = require('gulp-livereload'), | |
sourcemaps = require('gulp-sourcemaps'), | |
del = require('del'); | |
var bower_path = "./vendor/bower_components"; | |
var resource_path = "./resources/assets"; | |
var paths = { | |
'jquery' : bower_path + "/jquery/dist", | |
'bootstrap' : bower_path + "/bootstrap-sass-official/assets", | |
'fontawesome' : bower_path + "/font-awesome", | |
'datetimepicker' : bower_path + "/soundasleep-bootstrap-datetimepicker-sass/src", | |
'datetimepicker_js' : bower_path + "/eonasdan-bootstrap-datetimepicker/src", | |
'moment' : bower_path + "/moment" | |
}; | |
// Copy dependencies style to resources | |
gulp.task('style-resources', function() { | |
return gulp.src([ | |
paths.bootstrap + '/stylesheets/**/*.scss', | |
paths.fontawesome + '/scss/**/*.scss', | |
paths.datetimepicker + '/sass/**/*.scss' | |
]) | |
.pipe(gulp.dest(resource_path + '/sass')) | |
; | |
}); | |
// Styles | |
gulp.task('styles', function() { | |
return sass(resource_path + '/sass/app.scss',{ | |
loadPath: [ | |
paths.bootstrap + '/stylesheets', | |
paths.fontawesome + '/scss', | |
paths.datetimepicker + '/sass' | |
], | |
style: 'expanded', | |
compass: true, | |
verbose: true, | |
noCache: true, | |
sourcemap: true | |
}) | |
.on('error', function (err) { | |
console.log('Error!', err.message); | |
}) | |
.pipe(sourcemaps.init()) | |
.pipe(autoprefixer({ | |
browers: [ | |
'last 2 version', | |
'safari 5', | |
'ie 8', | |
'ie 9', | |
'opera 12.1', | |
'ios 6', | |
'android 4' | |
], | |
cascade: false | |
})) | |
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../../../scss/'})) | |
.pipe(concat('app.css')) | |
.pipe(gulp.dest('./public/assets/css')) | |
.pipe(rename({ suffix: '.min' })) | |
.pipe(minifyCSS({ | |
advanced: true, | |
keepBreaks: false, | |
keepSpecialComments : 0, | |
benchmark: true | |
})) | |
.pipe(concat('app.min.css')) | |
.pipe(gulp.dest('public/css')) | |
.pipe(notify({ message: 'Styles task complete' })) | |
.pipe(livereload()); | |
}); | |
// Scripts | |
gulp.task('scripts', function() { | |
return gulp.src([ | |
resource_path + '/javascripts/app.js', | |
paths.jquery + '/jquery.js', | |
paths.bootstrap + '/javascripts/bootstrap.min.js', | |
paths.moment + '/moment.js', | |
paths.moment + '/locale/th.js', | |
paths.datetimepicker_js + '/js/bootstrap-datetimepicker.js' | |
]) | |
.pipe(jshint('.jshintrc')) | |
.pipe(jshint.reporter('default')) | |
.pipe(concat('app.js')) | |
.pipe(gulp.dest('public/assets/js')) | |
.pipe(rename({ suffix: '.min' })) | |
.pipe(uglify()) | |
.pipe(gulp.dest('public/js')) | |
.pipe(notify({ message: 'Scripts task complete' })) | |
.pipe(livereload()); | |
}); | |
// Images | |
gulp.task('images', function() { | |
return gulp.src('resources/assets/images/**/*') | |
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))) | |
.pipe(gulp.dest('public/imgs')) | |
.pipe(notify({ message: 'Images task complete' })) | |
.pipe(livereload()); | |
}); | |
// Fonts | |
gulp.task('fonts', function() { | |
return gulp.src([ | |
paths.fontawesome + '/fonts/**/*', | |
paths.bootstrap + '/fonts/**/*' | |
]) | |
.pipe(gulp.dest('public/fonts')); | |
}); | |
// Clean | |
gulp.task('clean', function(cb) { | |
del(['public/assets/css', 'public/assets/js', 'public/assets/images'], cb); | |
}); | |
// Watch | |
gulp.task('watch', function() { | |
// Watch .scss files | |
gulp.watch('resources/assets/sass/**/*.scss', ['styles']); | |
// Watch .js files | |
gulp.watch('resources/assets/javascripts/**/*.js', ['scripts']); | |
// Watch image files | |
gulp.watch('resources/assets/images/**/*', ['images']); | |
// Create LiveReload server | |
livereload.listen(); | |
// Watch any files in dist/, reload on changed | |
gulp.watch(['resources/**', 'app/*.php', 'app/Http/routers.php', 'app/Http/Controllers/*.php', 'database/**' ]).on('change', livereload.changed); | |
}); | |
// Default task | |
gulp.task('default', ['clean'], function() { | |
gulp.start('styles', 'scripts', 'images', 'fonts'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment