Created
March 10, 2018 16:23
-
-
Save jasonsnider/f65eebcfa5ddc47107c9d36df936d5fc to your computer and use it in GitHub Desktop.
My Go To Gulp File
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'); | |
var watch = require('gulp-watch'); | |
var cleanCSS = require('gulp-clean-css'); | |
var uglify = require('gulp-uglify'); | |
var rename = require('gulp-rename'); | |
var concat = require('gulp-concat'); | |
var merge = require('merge-stream'); | |
var scss = require('gulp-scss'); | |
function version(){ | |
var now = new Date(), | |
Y = now.getFullYear(), | |
m = now.getMonth()+1, | |
d = now.getDate(), | |
H = now.getHours(), | |
i = now.getMinutes(), | |
s = now.getSeconds(); | |
if(H < 10) { | |
H = '0' + H; | |
} | |
if(i < 10) { | |
i = '0' + i; | |
} | |
if(s < 10) { | |
s = '0' + s; | |
} | |
return String(10000*Y + 100*m + d + '.' + H + i + s); | |
} | |
gulp.task('default', ['watch']); | |
gulp.task('build-css', function(){ | |
var full = gulp.src([ | |
'public/src/scss/main.scss' | |
]) | |
. pipe(scss()) | |
. pipe(concat('default.css')) | |
. pipe(gulp.dest('public/dist/css')); | |
var min = gulp.src([ | |
'public/src/scss/main.scss' | |
]) | |
. pipe(scss()) | |
. pipe(cleanCSS()) | |
. pipe(concat('default.min.' + version() + '.css')) | |
. pipe(gulp.dest('public/dist/css')); | |
return merge(full, min); | |
}); | |
gulp.task('build-js', function() { | |
var full = gulp.src([ | |
'public/src/js/main.js' | |
]) | |
.pipe(concat('default.js')) | |
.pipe(gulp.dest('public/dist/js')); | |
var min = gulp.src([ | |
'public/src/js/main.js' | |
]) | |
.pipe(concat('default.min.' + version() + '.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('public/dist/js')); | |
return merge(full, min); | |
}); | |
gulp.task('watch', function(){ | |
gulp.watch('./public/src/scss/**/*.scss', ['build-css']); | |
gulp.watch('./public/src/js/**/*.js', ['build-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
"devDependencies": { | |
"gulp": "^3.9.1", | |
"gulp-clean-css": "^3.9.2", | |
"gulp-concat": "^2.6.1", | |
"gulp-rename": "^1.2.2", | |
"gulp-scss": "^1.4.0", | |
"gulp-uglify": "^3.0.0", | |
"gulp-watch": "^5.0.0", | |
"merge-stream": "^1.0.1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment