Skip to content

Instantly share code, notes, and snippets.

@kentliau
Last active August 1, 2016 07:48
Show Gist options
  • Save kentliau/9050032 to your computer and use it in GitHub Desktop.
Save kentliau/9050032 to your computer and use it in GitHub Desktop.
Gulpfile configuration for Laravel
var //source path
src_scripts = 'public/assets_src/js/*.js',
src_styles = 'public/assets_src/less/**/app.less',
src_images = 'public/assets_src/img/**/*',
src_template = 'app/views/partial/**/*.dot',
//watch path
watch_scripts = 'public/assets_src/js/**/*.js',
watch_styles = 'public/assets_src/less/**/*.less',
watch_images = 'public/assets_src/img/**/*',
watch_template = 'app/views/partial/**/*.dot',
//builds and clean path
build_scripts = 'public/assets/js/',
build_styles = 'public/assets/css/',
build_images = 'public/assets/img/'
build_template = {
client: 'public/assets/partial/',
server: 'app/views/_partial/'
};
// Load plugins
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')({camelize:false}), //autoload plugins
// less = require('gulp-less'),
// 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'),
// clean = require('gulp-clean'),
// concat = require('gulp-concat'),
// notify = require('gulp-notify'),
// cache = require('gulp-cache'),
// browserify = require('gulp-browserify'),
// livereload = require('gulp-livereload'),
refresh = require('gulp-livereload'),
server = require('tiny-lr')();
var beep = function(){
plugins['util'].beep();
}
// Styles
gulp.task('styles', function() {
return gulp.src(src_styles)
// .pipe(plugins['plumber']())
.pipe(plugins['less']()
.on('error', beep)
.on('error', plugins['notify']
.onError({ title: "ERROR",
message: "Error: <%= error.message %>" })))
.pipe(plugins['autoprefixer'](
'last 2 version',
'safari 5',
'ie 8',
'ie 9',
'opera 12.1',
'ios 6',
'android 4'
))
.pipe(gulp.dest( build_styles ))
.pipe(plugins['rename']({ suffix: '.min' }))
.pipe(plugins['minify-css']())
.pipe(refresh(server))
.pipe(gulp.dest( build_styles ))
.pipe(plugins['notify']({ title: 'OK', message: 'Styles task complete' }));
});
// Scripts
gulp.task('scripts', function() {
return gulp.src(src_scripts)
// .pipe(plugins['jshint']('.jshintrc'))
// .pipe(plugins['jshint']['reporter']('default'))
// .pipe(plugins['concat']('main.js'))
.pipe(plugins['browserify']()
.on('error', beep)
.on('error', plugins['notify']
.onError({ title: "ERROR",
message: "Error: <%= error.message %>" })))
.pipe(gulp.dest(build_scripts))
.pipe(plugins['rename']({ suffix: '.min' }))
.pipe(plugins['uglify']())
.pipe(refresh(server))
.pipe(gulp.dest(build_scripts))
.pipe(plugins['notify']({ title: 'OK', message: 'Scripts task complete' }));
});
gulp.task('templates', function() {
gulp.src( src_template )
// .pipe(plugins['plumber']())
.pipe(plugins['dot-precompiler']({
dictionary:'render',
selfcontained:true,
append:true
})
.on('error', beep)
.on('error', plugins['notify']
.onError({ title: "ERROR",
message: "Error: <%= error.message %>" })))
// Build multiple compressed version
.pipe(plugins['rename']({ extname: '.blade.php' }))
.pipe(plugins['uglify']())
.pipe(gulp.dest( build_template['server'] ))
// Build a concatenated version in public
.pipe(plugins['concat']('all.min.js'))
.pipe(plugins['header']('window.render=window.render||{};'))
.pipe(plugins['uglify']())
.pipe(gulp.dest( build_template['client'] ))
.pipe(plugins['notify']({ title: 'OK', message: 'Templates task complete' }));
});
// Images
gulp.task('images', function() {
return gulp.src(src_images)
.pipe(plugins['cache'](plugins['imagemin']({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(refresh(server))
.pipe(gulp.dest(build_images))
.pipe(plugins['notify']({
title: 'OK',
message: 'Images task complete'
}));
});
// Clean
gulp.task('clean', function() {
return gulp.src( [
build_styles,
build_scripts,
build_images,
build_template['client'],
build_template['server']
], {read: false})
.pipe(plugins['clean']())
.pipe(plugins['notify']({
title: 'OK',
message: 'Cleaned all builds'
}));
});
// Default task
gulp.task('default', ['clean'], function() {
gulp.start(
'styles',
'scripts',
'images',
'templates'
);
});
// Watch
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
console.log(err);
};
// Watch .less files
gulp.watch( watch_styles , ['styles']);
// Watch .js files
gulp.watch( watch_scripts , ['scripts']);
// Watch image files
gulp.watch( watch_images , ['images']);
// Watch template files
gulp.watch( watch_template , ['templates']);
});
});
{
"name": "name",
"version": "0.0.1",
"description": "description",
"author": "Kent Liau",
"license": "MIT",
"readmeFilename": "./../readme.md",
"dependencies": {
"gulp": "latest",
"gulp-autoprefixer": "latest",
"gulp-cache": "latest",
"gulp-clean": "latest",
"gulp-concat": "latest",
"gulp-imagemin": "latest",
"gulp-jshint": "latest",
"gulp-less": "latest",
"gulp-livereload": "latest",
"gulp-minify-css": "latest",
"gulp-notify": "latest",
"gulp-rename": "latest",
"gulp-uglify": "latest",
"tiny-lr": "latest",
"gulp-load-plugins": "latest",
"gulp-browserify": "latest",
"gulp-header": "latest",
"gulp-dot-precompiler": "latest",
"gulp-util": "latest",
"gulp-plumber": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment