-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
86 lines (75 loc) · 2.05 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
const { src, dest, watch, series, parallel } = require('gulp');
const closureCompiler = require('google-closure-compiler').gulp();
const del = require('del');
const browserSync = require('browser-sync');
const htmlmin = require('gulp-htmlmin');
const concat = require('gulp-concat');
const zip = require('gulp-zip');
const cleanCSS = require('gulp-clean-css');
function cleanDist(done) {
del.sync(['docs']);
return done();
}
function archive() {
const d = new Date();
const version = `${d.getMonth() + 1}_${d.getDate()}_${d.getHours()}`;
return src('docs/**/*')
.pipe(zip(`app_${version}.zip`))
.pipe(dest('submission'));
}
function minifyHTML() {
return src('src/*.html')
.pipe(
htmlmin({
collapseWhitespace: true,
})
)
.pipe(dest('docs'));
}
function copyAssets() {
return src('src/assets/*').pipe(dest('docs/assets/'));
}
function minifyCSS() {
return src('src/*.css').pipe(cleanCSS()).pipe(dest('docs'));
}
function compile() {
return src('src/js/**/*.js')
.pipe(
closureCompiler({
compilation_level: 'ADVANCED',
warning_level: 'VERBOSE',
language_out: 'ECMASCRIPT6',
js_output_file: 'app.js',
})
)
.pipe(dest('docs'));
}
function compileDev() {
return src('src/js/**/*.js').pipe(concat('app.js')).pipe(dest('docs'));
}
function startServer(done) {
browserSync.init({
server: {
baseDir: './docs/',
},
});
done();
}
function reloadBrowser(done) {
browserSync.reload();
done();
}
function watchSource(done) {
watch('src/**/*', series(exports.default, reloadBrowser));
done();
}
exports.build = series(
cleanDist,
parallel(minifyHTML, minifyCSS, copyAssets, compile)
);
exports.default = series(
cleanDist,
parallel(minifyHTML, minifyCSS, copyAssets, compileDev)
);
exports.watch = series(exports.default, startServer, watchSource);
exports.zip = series(exports.build, archive);