Created
December 11, 2014 04:13
-
-
Save michaelcolenso/c9b911c3c3a0cff36e63 to your computer and use it in GitHub Desktop.
gulp task to deploy to s3
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
// Publish to Amazon S3 / CloudFront | |
gulp.task('deploy', function () { | |
var awspublish = require('gulp-awspublish'); | |
var aws = { | |
"key": process.env.AWS_KEY, | |
"secret": process.env.AWS_SECRET, | |
"bucket": 'XXXXXXXX', | |
"region": 'us-standard', | |
"distributionId": 'XXXXXXXX' | |
}; | |
var publisher = awspublish.create(aws); | |
var headers = { | |
'Cache-Control': 'max-age=315360000, no-transform, public' | |
}; | |
return gulp.src('build/**') | |
.pipe($.if('**/robots.txt', !argv.production ? $.replace('Disallow:', 'Disallow: /') : $.util.noop())) | |
// Add a revisioned suffix to the filename for each static asset | |
.pipe($.revAll({ | |
ignore: [ | |
/^\/apple-touch-icon-precomposed.png$/g, | |
/^\/browserconfig.xml$/g, | |
/^\/crossdomain.xml$/g, | |
/^\/error.html$/g, | |
/^\/humans.txt$/g, | |
/^\/robots.txt$/g | |
] | |
})) | |
// Gzip, set Content-Encoding headers | |
.pipe(awspublish.gzip()) | |
// Publisher will add Content-Length, Content-Type and headers specified above | |
// If not specified it will set x-amz-acl to public-read by default | |
.pipe(publisher.publish(headers)) | |
// Create a cache file to speed up consecutive uploads | |
.pipe(publisher.cache()) | |
// Print upload updates to console | |
.pipe(awspublish.reporter()) | |
// Updates the Default Root Object of a CloudFront distribution | |
.pipe($.cloudfront(aws)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
excellent!
thanks for posting