Created
May 22, 2017 12:28
-
-
Save mutuadavid93/b63c4afa25e18e8459a7cd4e4ec421fb to your computer and use it in GitHub Desktop.
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'), | |
uglify = require('gulp-uglify'), | |
concat = require('gulp-concat'), | |
gulpif = require('gulp-if'), | |
gutil = require('gulp-util'), | |
browserify = require('gulp-browserify'), | |
compass = require('gulp-compass'), | |
htmlmin = require('gulp-htmlmin'), | |
cssmin = require('gulp-minify-css'), | |
connect = require('gulp-connect'); | |
var env, js1, styleForm; | |
env = process.env.NODE_ENV || 'development'; | |
if(env === 'development') { | |
outputDir = '_/development/'; | |
styleForm = 'compressed'; | |
}else { | |
outputDir = '_/production/'; | |
styleForm = 'expanded'; | |
} | |
js1 = [ | |
'_/components/js/myscript.js', | |
'_/components/js/jquery.js' | |
]; | |
var sassFiles = ['_/components/sass/**/*.scss']; | |
var htmlSource = ['./index.html']; | |
gulp.task('js', function () { | |
gulp.src(js1) | |
.pipe(concat("myscript.js")) | |
.on('error', gutil.log) | |
.pipe(gulpif(env === "production", uglify())) | |
.pipe(gulp.dest(outputDir+"js")) | |
.pipe(connect.reload()); | |
}); | |
// take care of sass, susy and breakpoint | |
gulp.task('compass', function () { | |
gulp.src(sassFiles) | |
.pipe(compass({ | |
sass: '_/components/sass', | |
css: outputDir + 'css', | |
images: outputDir + 'images', | |
style: styleForm, | |
require: ['susy', 'breakpoint'] | |
})) | |
.on('error', gutil.log) | |
.pipe(connect.reload()); | |
}); | |
// html task | |
gulp.task('html', function () { | |
gulp.src('./index.html') | |
.pipe(gulpif(env === 'production', htmlmin({collapseWhitespace: true}))) | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir))) | |
.pipe( gulpif(env === 'development', gulp.dest(outputDir))) | |
.pipe(connect.reload()); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch(sassFiles, ['compass']); | |
gulp.watch(js1, ['js']); | |
gulp.watch(htmlSource, ['html']); | |
}); | |
gulp.task('connect', function() { | |
connect.server({ | |
root: outputDir, | |
livereload: true | |
}); | |
}); | |
gulp.task('default', ['js', 'connect','html', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment