Created
June 7, 2016 19:38
-
-
Save marionava/6ca5d72f2fff3e4bd98ee4d1982e7e78 to your computer and use it in GitHub Desktop.
Gulp File with watch, notify, minify, live reload, concat and source maps
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
var gulp = require('gulp'), | |
uglify = require('gulp-uglify'), | |
concat = require('gulp-concat'), | |
imagemin = require('gulp-imagemin'), | |
minifyCSS = require('gulp-clean-css'), | |
watch = require('gulp-watch'), | |
livereload = require('gulp-livereload'), | |
notify = require('gulp-notify'); | |
sourcemaps = require('gulp-sourcemaps'); | |
/* Tarea que combina todos los js en uno solo, los minifica, | |
les quita los debug del código y los guarda en la carpeta pública*/ | |
gulp.task('js', function () { | |
gulp.src([ | |
'./app/js/jquery.js', | |
'./app/js/jquery-migrate-1.2.1.min.js', | |
'./app/js/jquery.easing.1.3.js', | |
'./app/js/jquery.mobilemenu.js', | |
'./app/js/jquery.equalheights.js', | |
'./app/js/modal.js', | |
'./app/js/TMForm.js', | |
'./app/js/camera.js', | |
'./app/js/bootstrap-filestyle.js', | |
'./app/js/bootstrap.min.js', | |
'./app/js/jquery.ui.totop.js', | |
'./app/js/tmstickup.js', | |
'./app/js/superfish.js', | |
'./app/js/jquery.multibackground.min.js', | |
'./app/js/tm-scripts.js', | |
'./app/js/wow/wow.js', | |
'./app/js/wow/device.min.js', | |
//'./app/js/jquery.mobile.customized.min.js', // Provoca errores | |
'./app/js/stellar/jquery.stellar.js', | |
'./app/js/jquery.mousewheel.min.js', | |
'./app/js/jquery.simplr.smoothscroll.min.js', | |
]) | |
.pipe(sourcemaps.init({debug:true})) | |
.pipe(concat('all.js')) | |
.pipe(uglify({ compress: true })) | |
.on('error', function (err) { // Te permite capturar los errores de tus js | |
console.log(err); | |
}) | |
.pipe(sourcemaps.write('../js')) | |
.pipe(gulp.dest('./public/js')) | |
.pipe(livereload()); | |
}); | |
/* Minificación de CSS */ | |
gulp.task('css', function() { | |
gulp.src('./app/css/**/*.css') | |
.pipe(sourcemaps.init({debug:true})) | |
.pipe(concat('all.css')) | |
.pipe(minifyCSS()) | |
.pipe(sourcemaps.write('../css')) | |
.pipe(gulp.dest('./public/css')) | |
.pipe(livereload()); | |
}); | |
/* Recarga las páginas php cuando son cambiadas */ | |
gulp.task('reload', function() { | |
gulp.src('./public/**/*.php') | |
.pipe(livereload()); | |
}) | |
/* Escucha todos los cambios a css, js y php */ | |
gulp.task('watch', function(){ | |
livereload.listen(); | |
var css_watcher = gulp.watch('./app/css/**/*.css',['css']); | |
css_watcher.on('change', function(event) { | |
notification('CSS', event); // Funcion que manda una notificación a la pantalla | |
}); | |
var js_watcher = gulp.watch('./app/js/**/*.js',['js']); | |
js_watcher.on('change', function(event) { | |
notification('JS', event); | |
}); | |
gulp.watch('./public/**/*.php').on('change', function(event) { | |
notification('PHP', event); | |
gulp.src(event.path) | |
.pipe(livereload()); //Vuelve a cargar el archivo que fue modificado | |
}); | |
}); | |
/* Optimizar las imagenes del directorio */ | |
gulp.task('images', function () { | |
var imgSrc = './app/img/**/*', | |
imgDst = './public/img'; | |
gulp.src(imgSrc) | |
.pipe(imagemin()) | |
.pipe(gulp.dest(imgDst)); | |
}); | |
/* Copia las fuentes de la aplicación al público */ | |
gulp.task('fonts', function () { | |
gulp.src('./app/fonts/**') | |
.pipe(gulp.dest('./public/fonts')); | |
}); | |
gulp.task('default', [ 'js', 'css', 'images', 'fonts', 'watch']); | |
function notification(msg, event) | |
{ | |
return gulp.src('').pipe(notify({ | |
title : msg, | |
message : 'Archivo ' + event.path + ' fue ' + event.type, | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment