-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
66 lines (51 loc) · 1.8 KB
/
Copy pathgulpfile.js
File metadata and controls
66 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const gulp = require('gulp');
const awspublish = require('gulp-awspublish');
const AWS = require('aws-sdk');
const merge = require('merge-stream');
const minifyJs = require('gulp-uglify');
const minifyHTML = require('gulp-htmlmin');
const minifyCss = require('gulp-clean-css');
function deploy() {
// create a new publisher using S3 options
// http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
const publisher = awspublish.create({
region: process.env.AWS_REGION,
params: {
Bucket: process.env.AWS_BUCKET,
},
credentials: new AWS.SharedIniFileCredentials({ profile: process.env.AWS_PROFILE }),
}, {
cacheFileName: 'your-cache-location',
});
// define custom headers
const headers = {
'Cache-Control': 'max-age=315360000, no-transform, public',
};
const push = gulp.src('./public/**')
// publisher will add Content-Length, Content-Type and headers specified above
.pipe(awspublish.gzip({ ext: '' }))
// 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());
return push;
}
gulp.task('deploy', deploy);
function ready() {
const css = gulp.src('../public/css/*.css')
.pipe(minifyCss())
.pipe(gulp.dest('./public/css'));
const js = gulp.src('../public/js/*.js')
.pipe(minifyJs())
.pipe(gulp.dest('./public/js'));
const html = gulp.src('../public/*.html')
.pipe(minifyHTML())
.pipe(gulp.dest('./public'));
const media = gulp.src('../public/media/*')
.pipe(gulp.dest('./public/media'));
return merge(css, js, html, media);
}
gulp.task('ready', ready);
gulp.task('default', ['ready', 'deploy']);