-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (85 loc) · 2.86 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var fs = require('fs');
var gulp = require('gulp');
var watch = require('gulp-watch');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var webserver = require('gulp-webserver');
var awspublish = require('gulp-awspublish');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var rename = require('gulp-rename');
var addsrc = require('gulp-add-src');
var concat = require('gulp-concat');
var merge = require('merge-stream');
gulp.task('watch', function() {
gulp.watch('./sass/**/*.scss', ['sass']);
gulp.watch('./js/**/*.js', ['js']);
});
gulp.task('sass', function () {
gulp.src('./sass/*.scss')
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/'));
});
gulp.task('js', function() {
var bundler = browserify({
entries: ['./js/app.js'],
debug: true,
});
var bundle = function() {
return bundler
.bundle()
.on('error', function(err) {
console.log(err.toString());
this.emit("end");
})
.pipe(source('app.js'))
.pipe(buffer())
.pipe(addsrc('./js/vendor/*.js'))
.pipe(concat('playwell.min.js'))
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/'));
};
return bundle();
});
gulp.task('webserver', function() {
gulp.src('./')
.pipe(webserver({
livereload: true,
directoryListing: true,
open: true
}));
});
gulp.task('publish', function() {
var credentials = JSON.parse(fs.readFileSync('aws-credentials.json', 'utf8'));
var publisher = awspublish.create({
params: {
Bucket: 'join.playwell.co'
},
region: 'us-west-2',
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
});
var headers = {
'Cache-Control': 'max-age=300, no-transform, public'
};
var gzipped = gulp.src(['./*.js', './*.css', './*.html', './*.map'], { cwd: "./public/" })
.pipe(awspublish.gzip());
var images = gulp.src('./images/*', { cwd: "./public/" })
.pipe(rename({dirname: 'images'}));
var other = gulp.src(['./*', '!./*.js', '!./*.css', '!./*.html', '!./*.map'], { cwd: "./public/" });
return merge(gzipped, images, other)
.pipe(publisher.publish())
.pipe(publisher.cache())
.pipe(awspublish.reporter());
});
gulp.task('build', ['sass', 'js']);
gulp.task('default', ['sass', 'js', 'watch', 'webserver']);