This recipe demonstrates how to set up AWS S3 deployment task.
Install the gulp-awspublish gulp plugin:
$ npm install --save-dev gulp-awspublish
Add this task to your gulpfile.js
. It will run build
task before deploying:
gulp.task('deploy', ['default'], () => {
// create a new publisher
const publisher = $.awspublish.create({
params: {
'Bucket': '...'
}
});
// define custom headers
const headers = {
'Cache-Control': 'max-age=315360000, no-transform, public'
};
return gulp.src('dist/**/*.*')
.pipe(publisher.publish(headers))
.pipe(publisher.sync())
.pipe(publisher.cache())
.pipe($.awspublish.reporter());
});
.awspublish-*
publisher.cache()
creates a through stream that creates or updates a cache file using file s3 path and file etag. Consecutive runs of publish will use this file to avoid reuploading identical files.
Run the following command to deploy:
$ gulp deploy
It is highly recommended to enable asset revisioning.