forked from dkarchmer/django-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
59 lines (50 loc) · 1.57 KB
/
gulpfile.js
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
/**
* Gulpfile used to build static CSS/JS/Images used by django templates
*/
var gulp = require('gulp');
var chug = require( 'gulp-chug' );
var awspublish = require('gulp-awspublish');
var cloudfront = require("gulp-cloudfront");
var del = require('del');
var rename = require('gulp-rename');
gulp.paths = {
src: {
base: './webapp'
},
statics: './staticfiles',
dist: './staticfiles/dist',
templates: 'server/templates/dist'
};
// EDIT with your own settings
var aws = {
params: {
Bucket: "mystaticbucket",
Region: "myawsregion"
},
"distributionId": "mycloudfrontdistributionid"
};
var publisher = awspublish.create(aws);
// One week = 604,800
var headers = {'Cache-Control': 'max-age=604800, no-transform, public'};
var index_header = {'Cache-Control': 'public, must-revalidate, proxy-revalidate, max-age=0'};
gulp.task('clean', function(cb) {
return del([gulp.paths.dist + '/*'], cb)
});
gulp.task( 'base', ['clean'], function () {
return gulp.src( gulp.paths.src.base +'/gulpfile.babel.js', { read: false } )
.pipe( chug({
tasks: [ ]
}) )
});
gulp.task('deploy', ['base'], function () {
return gulp.src([gulp.paths.statics + '/**', '!'+ gulp.paths.dist + '/**/index.html'])
.pipe(rename(function (path) {
path.dirname = 'static/' + path.dirname;
}))
.pipe(awspublish.gzip())
.pipe(publisher.publish(headers))
.pipe(publisher.cache())
.pipe(awspublish.reporter())
.pipe(cloudfront(aws));
});
gulp.task('default', ['base']);