-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
76 lines (64 loc) · 2.33 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
var gulp = require('gulp'),
zip = require('gulp-zip'),
watch = require('gulp-watch'),
jshint = require('gulp-jshint'),
gp_concat = require('gulp-concat'),
gp_uglify = require('gulp-uglify'),
imageop = require('gulp-image-optimization'),
minifyHTML = require('gulp-minify-html'),
rename = require('gulp-rename');
// All your paths for JS, HTML and Image files
var zip_files = ['game.js', 'index.html'], // Files to be added to the zip folder use "<directory goes here>/*" for all files inside the directory
js_files = ['js/main.js', 'scenes/*'], // All your JS files to be combined and minified
img_files = ['assets/*.png','assets/*.jpg','assets/*.gif','assets/*.jpeg', 'assets/**/*.png','assets/**/*.jpg','assets/**/*.gif','assets/**/*.jpeg'];
//Zip up the JS/HTML required for the game
gulp.task('zip', function () {
return gulp.src(zip_files, {base: "."})
.pipe(zip('game.zip'))
.pipe(gulp.dest('build'));
});
//Run this task once the game is ready to ship!
gulp.task('publish', ['build-js', 'build-html', 'zip']);
//Compress Images
//Todo: Test to see if it'll override images
gulp.task('images', function(cb) {
gulp.src(img_files).pipe(imageop({
optimizationLevel: 5,
progressive: true,
interlaced: true
})).pipe(gulp.dest('build/assets')).on('end', cb).on('error', cb);
});
//Minify the HTML
gulp.task('build-html', function() {
return gulp.src('./index.unmin.html')
.pipe(minifyHTML())
.pipe(rename('index.html'))
.pipe(gulp.dest('./build/'));
});
//Build the JS and minify
gulp.task('build-js', function() {
return gulp.src(js_files)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gp_uglify())
.pipe(gp_concat('game.js'))
.pipe(gulp.dest('./build/'));
});
//Build the JS without minifying
gulp.task('build-dev', function() {
return gulp.src(js_files)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gp_concat('game.js'))
.pipe(gulp.dest('./build/'));
});
//Watch Task
gulp.task('watch', function() {
gulp.watch('./index.unmin.html', ['build-html']);
gulp.watch(js_files, ['build-dev']);
gulp.watch(img_files, ['images']);
});
//Default Task
gulp.task('default', ['build-html', 'build-dev', 'images']);
//Legacy 'build' alias for build-dev task
gulp.task('build', ['build-dev']);