Created
September 13, 2017 16:50
-
-
Save marionava/f1018f45af16bd0fab113e9033b5488f to your computer and use it in GitHub Desktop.
Gulp configuration for web development
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'), | |
shell = require('gulp-shell'), | |
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/core.min.js', | |
'./app/js/script.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/images/**/*', | |
imgDst = './public/images'; | |
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