-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
121 lines (114 loc) · 2.84 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
const gulp = require('gulp');
const gulpBabel = require('gulp-babel');
const gulpConnect = require('gulp-connect');
const gulpHtmlclean = require('gulp-htmlclean');
const gulpHtmlmin = require('gulp-htmlmin');
const gulpMinifycss = require('gulp-minify-css');
const gulpUglify = require('gulp-uglify');
const gulpUtil = require('gulp-util');
const gulpConcat = require('gulp-concat');
function minify_css(done) {
gulp
.src([
'./dist/css/theme.css',
'./dist/css/style.css',
'./dist/css/index.css',
'./dist/css/fonts.css',
'./dist/css/loading.css',
])
.pipe(gulpMinifycss())
.pipe(gulpConcat('main.css'))
.pipe(gulp.dest('./dist/css'))
.pipe(gulpConnect.reload());
done();
}
function minify_photoswipe_css(done) {
gulp
.src('./dist/css/photoswipe.css')
.pipe(gulpMinifycss())
.pipe(gulp.dest('./dist/css'))
.pipe(gulpConnect.reload());
done();
}
function minify_html(done) {
gulp
.src('./dist/**/*.html')
.pipe(gulpHtmlclean())
.pipe(
gulpHtmlmin({
removeComments: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
}),
)
.pipe(gulp.dest('./dist'))
.pipe(gulpConnect.reload());
done();
}
function minify_js(done) {
// main-async.js
gulp
.src([
'./dist/js/mode.js',
'./dist/js/math-code.js',
'./dist/js/right-quote.js',
'./dist/js/fix-footnote.js',
'./dist/js/checkbox-list.js',
'./dist/js/hide-menu.js',
'./dist/js/beaudar.js',
'./dist/js/load-typekit.js',
])
.pipe(
gulpBabel({
presets: ['@babel/preset-env'],
}),
)
.pipe(gulpUglify())
.on('error', function (err) {
gulpUtil.log(gulpUtil.colors.red('[Error]'), err.toString());
})
.pipe(gulpConcat('main-async.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(gulpConnect.reload());
done();
// main.js
gulp
.src(['./dist/js/tableOfContents.v2.js'])
.pipe(
gulpBabel({
presets: ['@babel/preset-env'],
}),
)
.pipe(gulpUglify())
.on('error', function (err) {
gulpUtil.log(gulpUtil.colors.red('[Error]'), err.toString());
})
.pipe(gulpConcat('main.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(gulpConnect.reload());
done();
}
function minify_sw_js(done) {
gulp
.src('./dist/sw.js')
.pipe(
gulpBabel({
presets: ['@babel/preset-env'],
}),
)
.pipe(gulpUglify())
.on('error', function (err) {
gulpUtil.log(gulpUtil.colors.red('[Error]'), err.toString());
})
.pipe(gulp.dest('./dist'))
.pipe(gulpConnect.reload());
done();
}
exports.default = gulp.series(
minify_css,
minify_photoswipe_css,
minify_html,
minify_js,
minify_sw_js,
);