Created
September 21, 2016 15:52
-
-
Save aarongustafson/ba18fe460e01bf09eb49181c9bf1b6c4 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'), | |
path = require('path'), | |
folder = require('gulp-folders'), | |
gulpIf = require('gulp-if'), | |
insert = require('gulp-insert'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
notify = require('gulp-notify'), | |
rename = require('gulp-rename'), | |
source_folder = 'source/js', | |
destination_folder = 'deploy/j', | |
rename_serviceworker = rename({ | |
dirname: "../" | |
}); | |
gulp.task('scripts', folder(source_folder, function(folder){ | |
function createErrorHandler( name ) | |
{ | |
return function (err) { | |
console.error('Error from ' + name + ' in compress task', err.toString()); | |
}; | |
} | |
return gulp.src(path.join(source_folder, folder, '*.js')) | |
.pipe(concat(folder + '.js')) | |
.pipe(insert.prepend('(function(window,document){')) | |
.pipe(insert.append('}(this,this.document));')) | |
.pipe(insert.transform(function(contents, file){ | |
// insert a build time variable | |
var build_time = (new Date()).getTime() + ''; | |
return contents.replace( '{{BUILD_TIME}}', build_time ); | |
})) | |
.pipe(gulpIf(folder=='serviceworker',rename_serviceworker)) | |
.pipe(gulp.dest(destination_folder)) | |
.pipe(gulpIf(folder!='serviceworker',uglify().on('error', createErrorHandler('uglify')))) | |
.pipe(gulpIf(folder!='serviceworker',rename({suffix: '.min'}))) | |
.pipe(gulpIf(folder!='serviceworker',gulp.dest(destination_folder))) | |
.pipe(notify({ message: 'Scripts task complete' })); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment