Skip to content

Instantly share code, notes, and snippets.

@tacone
Last active August 29, 2015 14:23
Show Gist options
  • Save tacone/659ddff65b96f559635c to your computer and use it in GitHub Desktop.
Save tacone/659ddff65b96f559635c to your computer and use it in GitHub Desktop.
This is my gulpfile. There are many like it, but this one is mine.
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin'),
cache = require('gulp-cache');
var minifycss = require('gulp-minify-css');
var less = require('gulp-less');
var browserSync = require('browser-sync');
gulp.task('browser-sync', function() {
browserSync({
proxy: 'example.dev'
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('assets/frontend/images/**/*.*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('public/img/'));
});
var jsFiles = [
'bower_components/jquery/dist/jquery.js',
// ----------------
// bootstrap files
// ----------------
// 'bower_components/bootstrap/js/affix.js',
//'bower_components/bootstrap/js/alert.js',
//'bower_components/bootstrap/js/button.js',
'bower_components/bootstrap/js/carousel.js',
'bower_components/bootstrap/js/transition.js',
'bower_components/bootstrap/js/collapse.js',
'bower_components/bootstrap/js/dropdown.js',
// 'bower_components/bootstrap/js/modal.js',
//'bower_components/bootstrap/js/popover.js',
// 'bower_components/bootstrap/js/scrollspy.js',
'bower_components/bootstrap/js/tab.js',
//'bower_components/bootstrap/js/tooltip.js',
// lightbox image previews
'bower_components/fancybox/source/jquery.fancybox.js',
// jQuery form
'bower_components/jquery-form/jquery.form.js',
'bower_components/jquery-als/index.js',
'bower_components/chained/jquery.chained.js'
];
gulp.task('styles', function(){
gulp.src(['assets/frontend/less/app.less'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(less())
// actually breaks bootstrap own compatibility mixins
//.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('public/frontend/css/'))
//.pipe(rename({suffix: '.min'}))
//.pipe(minifycss())
//.pipe(gulp.dest('public/frontend/css/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts', function(){
var src = jsFiles;
src.push('assets/frontend/js/**/*.js')
return gulp.src(src)
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(gulp.dest('public/frontend/js/'))
//.pipe(rename({suffix: '.min'}))
//.pipe(uglify())
//.pipe(gulp.dest('public/frontend/js/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('default', ['styles', 'scripts', 'browser-sync'], function(){
gulp.watch("assets/frontend/less/**/*.less", ['styles']);
gulp.watch("assets/frontend/js/**/*.js", ['scripts']);
gulp.watch("assets/frontend/images/**/*.*", ['images']);
gulp.watch("app/views/**/*.html.twig", ['bs-reload']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment