This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgulpfile.js
112 lines (95 loc) · 2.81 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
var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var uglify = require('gulp-uglify');
var minifyInline = require('gulp-minify-inline');
var pump = require('pump');
var historyApiFallback = require('connect-history-api-fallback');
var fileinclude = require('gulp-file-include');
var browserSync = require('browser-sync').create();
var del = require('del');
var plumber = require('gulp-plumber');
var buildSpeaker = require('./src/build/profile.build.js');
gulp.task('compress', function() {
return pump([
gulp.src('src/*.js'),
uglify(),
gulp.dest('dist')
]);
});
gulp.task('clean', function () {
return del([
'dist/**',
'src/html-compiled/**',
]);
});
gulp.task('fileinclude', ['clean'], function(callback) {
return gulp.src(['src/html/*.html'])
.pipe(plumber())
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('src/html-compiled/'))
.pipe(browserSync.stream());
});
gulp.task('minify', function() {
return gulp.src('src/html/*.html')
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(minifyInline())
.pipe(gulp.dest('dist'));
});
gulp.task('minify-speaker', async function() {
await buildSpeaker();
return gulp.src('static/speaker/*.html')
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(minifyInline())
.pipe(gulp.dest('dist/speaker'));
});
gulp.task('copy', function() {
return gulp.src([
'src/_redirects',
'src/*.xml',
'src/*.txt',
'src/*.pdf'
])
.pipe(gulp.dest('dist'));
});
gulp.task('build', ['minify', 'minify-speaker', 'compress', 'copy']);
gulp.task('include-watch', ['fileinclude'], browserSync.reload);
gulp.task('watch', ['fileinclude', 'browser-sync'], function () {
"use strict";
gulp.watch("./src/html/**/*.html", ['include-watch']);
gulp.watch("./src/*.json", ['include-watch']);
});
gulp.task('watch-dist', ['build'], function () {
"use strict";
gulp.watch("./dist/*.html", browserSync.reload);
});
function simpleURLRewrite(req, res, next) {
if (req.url === '/') {
req.url = "/index";
}
if (req.url.indexOf('.') === -1) {
req.url += ".html";
}
return next();
}
// Static server
gulp.task('browser-sync', ['fileinclude'], function() {
browserSync.init({
server: {
baseDir: "./src/html-compiled/",
},
middleware: simpleURLRewrite,
});
});
gulp.task('browser-sync-dist', ['build'], function() {
browserSync.init({
server: {
baseDir: "./dist/",
},
middleware: simpleURLRewrite,
});
});
gulp.task('default', ['watch']);
gulp.task('dist', ['watch-dist', 'browser-sync-dist']);