-
-
Save mloayzagahona/e63540cb9b90aa82d905053bcce072ff to your computer and use it in GitHub Desktop.
Example Gulp task for scripts building using gulp-notify
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
/** | |
* Compile all JS files into the build directory | |
*/ | |
var scriptBootCount = 0; | |
gulp.task('scripts', ['load:config'], function() { | |
var hasErr; | |
return gulp.src(paths.scripts) | |
.pipe(gplumber({ | |
errorHandler: function(err) { | |
gutil.log(colors.red('ERROR DURING JS BUILD')); | |
notify({message: err.name + '\n' + err.message, title: config.title + ' - JS Error'}).write(err); | |
process.stdout.write(err.stack); | |
hasErr = err; | |
this.emit('end'); | |
}, | |
})) | |
.pipe(cache(babel({ // Cache output and pipe though Babel | |
presets: ['es2015'], | |
}), { | |
key: function(file) { | |
return [file.contents.toString('utf8'), file.stat.mtime, file.stat.size].join(''); | |
}, | |
success: function(file) { | |
gutil.log('Babel compile', colors.cyan(file.relative)); | |
return true; | |
}, | |
})) | |
.pipe(gulpIf(config.gulp.debugJS, sourcemaps.init())) | |
.pipe(concat('site.min.js')) | |
.pipe(replace("\"app\/", "\"\/app\/")) // Rewrite all literal paths to relative ones | |
.pipe(gulpIf(config.gulp.minifyJS, annotate())) | |
.pipe(gulpIf(config.gulp.minifyJS, uglify({mangle: false}))) | |
.pipe(gulpIf(config.gulp.debugJS, sourcemaps.write())) | |
.pipe(gulp.dest(paths.build)) | |
.on('end', function() { | |
if (!hasErr) | |
notify({ | |
title: config.title, | |
message: 'Rebuilt frontend scripts' + (++scriptBootCount > 1 ? ' #' + scriptBootCount : ''), | |
icon: __dirname + '/icons/angular.png', | |
}).write(0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment