Last active
January 8, 2016 18:54
-
-
Save vedovelli/08d28c4aa34a0eba5ebb to your computer and use it in GitHub Desktop.
Gulp + Duo + Browsersync + Uglify
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'); | |
var browserSync = require('browser-sync').create(); | |
var uglify = require('gulp-uglify'); | |
var exec = require('child_process').exec; | |
var srcDir = './src/**/*.js'; | |
var jsIn = './src/main.js'; | |
var jsOut = './build/main.js'; | |
gulp.task('default', ['browser-sync', 'duo', 'watch']); | |
gulp.task('browser-sync', function() { | |
browserSync.init({ | |
proxy: "screencast-duo.app", | |
notify: false | |
}); | |
}); | |
/** | |
* Pega o arquivo gerado pelo Duo e minifica | |
*/ | |
gulp.task('compress', function() | |
{ | |
return gulp.src(jsOut) | |
.pipe(uglify()) | |
.pipe(gulp.dest('dist')); | |
}); | |
/** | |
* Compila main.js (ver var jsIn acima) usando Duo. | |
*/ | |
gulp.task('duo', function() | |
{ | |
exec('duo --stdout ' + jsIn + ' > ' + jsOut, function (err, stdout, stderr) | |
{ | |
console.log(err); | |
console.log(stdout); | |
console.log(stderr); | |
}); | |
}); | |
/** | |
* | |
*/ | |
gulp.task('watch', function() { | |
gulp.watch(["**/*.html"]).on('change', browserSync.reload); | |
/** | |
* Sempre que o arquivo compilado pelo Duo for salvo, minifica e atualiza o browser | |
*/ | |
gulp.watch([jsOut], ['compress']).on('change', browserSync.reload); | |
/** | |
* Observa qualquer arquivo na pasta /src | |
*/ | |
gulp.watch([srcDir], ['duo']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment