Skip to content

Instantly share code, notes, and snippets.

@taylorsmithgg
Created April 21, 2017 17:26
Show Gist options
  • Save taylorsmithgg/4e951d363a892f56d7140394ab5a4cec to your computer and use it in GitHub Desktop.
Save taylorsmithgg/4e951d363a892f56d7140394ab5a4cec to your computer and use it in GitHub Desktop.
Simple Gulp for Babel, Gulp, and Elastic Beanstalk
'use strict'
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
const gutil = require('gulp-util');
const babel = require('gulp-babel');
const gulpEbDeploy = require('gulp-elasticbeanstalk-deploy');
const standard = require('gulp-standard');
const paths = {
scripts: ['*.js', 'src/**/*.js', '!node_modules/**/*.js'],
images: '**/*.png',
build: 'dist'
};
// Not all tasks need to use streams
// A gulpfile is just another node program and you can use any package available on npm
gulp.task('clean', function() {
// You can use multiple globbing patterns as you would with `gulp.src`
return del(paths.build);
});
gulp.task('build', ['clean'], function() {
// Minify and copy all JavaScript (except vendor scripts)
// with sourcemaps all the way down
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(
babel({}).on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
this.emit('end');
}))
.pipe(
uglify()
.on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
this.emit('end');
}))
.pipe(concat('all.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.build));
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['build']);
gulp.watch(paths.images, ['images']);
});
gulp.task('deploy', function() {
return gulp.src([
'config/**/*',
'lib/**/*',
'docs/**/*.html',
'package.json'
], { base: './' })
.pipe(gulpEbDeploy({
// name: 'my-application', // optional: If not set, the name from package.json will be used
// version: '1.0.0', // optional: If not set, the version from package.json will be used
timestamp: true, // optional: If set to false, the zip will not have a timestamp
waitForDeploy: true, // optional: if set to false the task will end as soon as it starts deploying
amazon: {
// accessKeyId: "< your access key (fyi, the 'short' one) >", // optional
// secretAccessKey: "< your secret access key (fyi, the 'long' one) >", // optional
// signatureVersion: "v4", // optional
region: 'us-east-1',
bucket: 'elasticbeanstalk-apps',
applicationName: 'MyApplication',
environmentName: 'my-application-env'
}
}).on('error', function(err){
gutil.log(gutil.colors.red('[Error]'), err.toString());
this.emit('end');
}))
})
gulp.task('standard', function () {
return gulp.src(paths.scripts)
.pipe(standard())
.pipe(standard.reporter('default', {
breakOnError: true,
quiet: true
}))
})
// Copy all static images
// gulp.task('images', ['clean'], function() {
// return gulp.src(paths.images)
// // Pass in options to the task
// .pipe(imagemin({optimizationLevel: 5}))
// .pipe(gulp.dest('build/img'));
// });
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['clean', 'watch', 'build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment