-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (118 loc) · 3.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"use strict";
const gulp = require('gulp');
const pug = require('pug');
const vulcanize = require('gulp-vulcanize');
const rename = require('gulp-rename');
const $ = require('gulp-load-plugins')();
const runSequence = require('run-sequence');
const merge = require('merge-stream');
const minifyInline = require('gulp-minify-inline')
const path = require('path');
const clean = require('gulp-clean');
const DIST = 'game';
var dist = function(subpath) {
return !subpath?DIST:path.join(DIST, subpath);
};
function swallowError (error) {
// If you want details of the error in the console
console.log("ERROR",error.toString())
this.emit('end')
}
//=====================================================|
var imageOptimizeTask = function(src, dest) {
return gulp.src(src)
.pipe($.imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(dest))
.pipe($.size({title: 'images'}));
};
var optimizeHtmlTask = function(src, dest) {
return gulp.src(src)
// Concatenate and minify JavaScript
.pipe($.if('*.js', $.uglify({preserveComments: 'none'})))
// Concatenate and minify styles
// In case you are still using useref build blocks
.pipe($.if('*.css', $.cleanCss()))
// Minify any HTML
.pipe($.if('*.html', $.minifyHtml({
quotes: true,
empty: true,
spare: true
})))
// Output files
.pipe(gulp.dest(dest))
.pipe($.size({
title: 'html'
}));
};
//=====================================================|
gulp.task('copy', function() {
var app = gulp.src([
'app/**/*',
'!app/bower_components',
'!app/*.pug',
'!app/elements.html',
], {
dot: true
}).pipe($.changed(dist('bower_components'))).pipe(gulp.dest(dist()));
// Copy over only the bower_components we need
// These are things which cannot be vulcanized
var bower = gulp.src([
'app/bower_components/{webcomponentsjs,promise-polyfill,trianglify,moment}/**/*'
]).pipe($.changed(dist('bower_components'))).pipe(gulp.dest(dist('bower_components')));
return merge(app, bower)
.pipe($.size({
title: 'copy'
}));
});
gulp.task('images', function() {return imageOptimizeTask(['app/public/**/*.png','app/public/**/*.ico','app/public/**/*.jpg'], dist('public'))});
gulp.task('html', function() {return optimizeHtmlTask(
['app/*.html','!app/elements.html'],
dist())
});
gulp.task('pug', function() {
return gulp.src(["app/*.pug"])
.pipe($.pug())
.on('error', swallowError)
.pipe(gulp.dest(dist()))
})
gulp.task('vulcanize', function() {
return gulp.src('app/elements.html')
.pipe(gulp.dest('app/bower_components'))
.pipe($.vulcanize({
stripComments: true,
inlineCss: true,
inlineScripts: true
}))
.pipe($.if('*.html', $.minifyHtml({
quotes: true,
empty: true,
spare: true
})))
.pipe(minifyInline())
.pipe(gulp.dest(dist()))
.pipe($.size({title: 'vulcanize'}));
});
//=====================================================|
gulp.task('watch', _ => {
gulp.watch("app/*.pug", ['pug']);
})
gulp.task('clean', _ => {
return gulp.src(['app/bower_components/elements*',dist("elements.html")], {read: false})
.pipe(clean());
})
//=====================================================|
gulp.task('restore', function(cb) {
runSequence(
['pug','images', 'vulcanize'],
'html', 'watch',
cb)
})
gulp.task('default', ['clean'], function(cb) {
runSequence(
'copy',
'restore',
cb);
});