Last active
April 10, 2019 21:13
-
-
Save antonioOrtiz/2abb5edc57142adb98b2 to your computer and use it in GitHub Desktop.
Revised gulpfile.js
This file contains hidden or 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'), | |
gutil = require('gulp-util'), | |
uglify = require('gulp-uglify'), | |
minifycss = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
filter = require('gulp-filter'), | |
sass = require('gulp-ruby-sass'), | |
concat = require('gulp-concat'), | |
plumber = require('gulp-plumber'), | |
notify = require('gulp-notify'), | |
addsrc = require('gulp-add-src'), | |
order = require('gulp-order'), | |
gulpif = require('gulp-if'), | |
open = require("gulp-open"), | |
minifyHTML = require('gulp-minify-html'), | |
imagemin = require('gulp-imagemin'), | |
pngcrush = require('imagemin-pngcrush'), | |
newer = require('gulp-newer'), | |
// webserver = require('gulp-webserver'), | |
streamqueue = require('streamqueue'), | |
autoprefixer = require('gulp-autoprefixer'); | |
// browserify = require('gulp-browserify'), | |
// fileinclude = require('gulp-file-include'), | |
// uncss = require('gulp-uncss'), | |
// var modRewrite = require('connect-modrewrite'); | |
var browserSync = require('browser-sync'); | |
var mainBowerFiles = require('main-bower-files'); | |
var env, | |
jsSources, | |
htmlSources, | |
sassSources, | |
outputDir; | |
htmlSources = [outputDir + '*.html']; | |
jsSources = ['components/js/**/*.js']; | |
sassSources = ['components/scss/**/*.scss']; | |
env = process.env.NODE_ENV || 'development'; | |
if (env === 'development') { | |
outputDir = 'builds/development/'; | |
} else { | |
outputDir = 'builds/production/'; | |
} | |
// Open an URL: | |
gulp.task('url', function() { | |
var options = { | |
url: "http://localhost:3000", | |
app: "google-chrome" | |
}; | |
return gulp.src(outputDir + 'index.html') | |
.pipe(open("", { | |
app: "google-chrome", | |
url: "http://localhost:3000" | |
})) | |
.pipe(plumber()); | |
}); | |
// browserSync task | |
gulp.task('browser-sync', function() { | |
browserSync({ | |
server: { | |
baseDir: outputDir | |
}, | |
}); | |
}); | |
gulp.task('scripts', function() { | |
return streamqueue({ | |
objectMode: true | |
}, | |
gulp.src('builds/development/bower_components/jquery/dist/jquery.js'), | |
gulp.src('builds/development/bower_components/fastclick/lib/fastclick.js'), | |
gulp.src('builds/development/bower_components/mixitup/build/jquery.mixitup.min.js'), | |
gulp.src('builds/development/bower_components/flexslider/jquery.flexslider.js'), | |
gulp.src('builds/development/bower_components/angular/angular.js'), | |
gulp.src('builds/development/bower_components/angular-animate/angular-animate.js'), | |
gulp.src('builds/development/bower_components/angular-route/angular-route.js'), | |
gulp.src('builds/development/bower_components/angular-ui-router/release/angular-ui-router.js'), | |
gulp.src('builds/development/bower_components/angular-flexslider/angular-flexslider.js'), | |
gulp.src('builds/development/bower_components/angular-foundation/mm-foundation-tpls.js'), | |
gulp.src('builds/development/bower_components/foundation/js/vendor/modernizr.js'), | |
gulp.src('components/js/rustyApp.js'), | |
gulp.src('components/js/share.js'), | |
gulp.src('builds/development/bower_components/uikit/js/uikit.js'), | |
gulp.src('builds/development/bower_components/foundation/js/foundation.js'), | |
gulp.src('builds/development/bower_components/scrollup/dist/jquery.scrollUp.min.js'), | |
gulp.src('components/js/index_scripts.js')) | |
.pipe(jshint()) | |
.pipe(concat('app.js')) | |
.pipe(gulpif(env === 'production', uglify())) | |
.pipe(plumber()) | |
.pipe(notify({ | |
message: "Script tasks have been completed!" | |
})) | |
.pipe(gulp.dest(outputDir + 'js')); | |
}); | |
gulp.task('css', function() { | |
return gulp.src('components/scss/**/*.scss') | |
.pipe(sass({style:'expanded'})) | |
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) | |
.pipe(addsrc(mainBowerFiles())) | |
.pipe(filter('*.css')) | |
.pipe(order([ | |
'normalize.css', | |
'builds/development/bower_components/foundation/css/foundation.css', | |
'builds/development/bower_components/ionicons/css/ionicons.css' | |
])) | |
.pipe(concat('main.css')) | |
.on('error', function(err) { | |
console.log(err.message); | |
}) | |
.pipe(plumber()) | |
.pipe(notify({ | |
message: "Sass tasks have been completed!" | |
})) | |
.pipe(gulpif(env === 'production', minifycss())) | |
.pipe(gulp.dest(outputDir + 'css')) | |
.pipe(browserSync.reload({ | |
stream: true | |
})); | |
}); | |
gulp.task('php', function() { | |
return gulp.src('builds/development/partials/mailer.php') | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir))) | |
.pipe(notify({ | |
message: "PHP tasks have been completed!" | |
})); | |
}); | |
gulp.task('html', function() { | |
return gulp.src('builds/development/**/*.html') | |
.pipe(gulpif(env === 'production', minifyHTML())) | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir))) | |
.pipe(notify({ | |
message: "HTML tasks have been completed!" | |
})); | |
}); | |
gulp.task('images', function() { | |
return gulp.src('builds/development/images/**/*.*') | |
.pipe(newer(outputDir + 'images')) | |
.pipe(gulpif(env === 'production', imagemin({ | |
interlaced: true, | |
progressive: true, | |
svgoPlugins: [{ | |
removeViewBox: false | |
}], | |
use: [pngcrush()] | |
}))) | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir + 'images'))); | |
}); | |
// Reload all Browsers | |
gulp.task('bs-reload', function() { | |
browserSync.reload(); | |
}); | |
gulp.task('fonts', function() { | |
return gulp.src('builds/development/fonts/**/*.*'), | |
gulp.src('builds/development/bower_components/fontawesome/fonts/*.*') | |
// .pipe(newer(outputDir + 'fonts')) | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir + 'fonts'))); | |
}); | |
//watch task | |
gulp.task('watch', function() { | |
gulp.watch('builds/development/**/*.html', ['bs-reload', 'html', 'webserver']); | |
gulp.watch('builds/development/partials/mailer.php', ['bs-reload', 'php']); | |
gulp.watch(outputDir + '*.html', ['bs-reload', 'url']); | |
gulp.watch(outputDir, ['fonts']); | |
gulp.watch('builds/development/images/**/*.*', ['bs-reload', 'images']); | |
gulp.watch(sassSources, ['bs-reload', 'css']); | |
gulp.watch(jsSources, ['bs-reload', 'scripts']); | |
// gulp.watch('builds/development/*.html', ['usemin']); | |
// gulp.watch('components/*.html', ['fileinclude']); | |
}); | |
gulp.task('default', ['watch', 'css', 'scripts', 'url', 'browser-sync', 'html', 'images', 'fonts', 'php']); | |
// gulp.task('default', ['watch', 'css', 'scripts', 'url', 'browser-sync', 'html', 'php', 'images', 'fonts']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment