forked from b3log/solo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (151 loc) · 4.88 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file frontend tool.
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.8.0.0, Nov 5, 2019
*/
'use strict'
const gulp = require('gulp')
const concat = require('gulp-concat')
const terser = require('gulp-terser')
const sass = require('gulp-sass')
const rename = require('gulp-rename')
const autoprefixer = require('gulp-autoprefixer')
const del = require('del')
function sassSkinProcess () {
return gulp.src('./src/main/resources/skins/*/css/*.scss').
pipe(sass({
outputStyle: 'compressed',
includePaths: ['node_modules'],
}).on('error', sass.logError)).
pipe(autoprefixer({
cascade: false,
})).
pipe(gulp.dest('./src/main/resources/skins/'))
}
function sassWatch () {
gulp.watch(['./src/main/resources/skins/*/css/*.scss'], sassSkinProcess)
gulp.watch(['./src/main/resources/scss/*.scss'], sassCommonProcess)
}
function sassCommonProcess () {
return gulp.src('./src/main/resources/scss/*.scss').
pipe(sass({
outputStyle: 'compressed',
includePaths: ['node_modules'],
}).on('error', sass.logError)).
pipe(autoprefixer({
cascade: false,
})).
pipe(gulp.dest('./src/main/resources/scss/'))
}
gulp.task('watch', gulp.series(sassWatch))
function minJS () {
// minify js
return gulp.src('./src/main/resources/js/*.js').
pipe(rename({suffix: '.min'})).
pipe(terser({
output: {
ascii_only: true,
},
})).
pipe(gulp.dest('./src/main/resources/js/'))
}
function miniAdmin () {
// concat js
const jsJqueryUpload = [
'./src/main/resources/js/admin/admin.js',
'./src/main/resources/js/admin/editor.js',
'./src/main/resources/js/admin/tablePaginate.js',
'./src/main/resources/js/admin/article.js',
'./src/main/resources/js/admin/comment.js',
'./src/main/resources/js/admin/articleList.js',
'./src/main/resources/js/admin/draftList.js',
'./src/main/resources/js/admin/pageList.js',
'./src/main/resources/js/admin/others.js',
'./src/main/resources/js/admin/linkList.js',
'./src/main/resources/js/admin/preference.js',
'./src/main/resources/js/admin/themeList.js',
'./src/main/resources/js/admin/pluginList.js',
'./src/main/resources/js/admin/userList.js',
'./src/main/resources/js/admin/categoryList.js',
'./src/main/resources/js/admin/commentList.js',
'./src/main/resources/js/admin/plugin.js',
'./src/main/resources/js/admin/main.js',
'./src/main/resources/js/admin/about.js']
return gulp.src(jsJqueryUpload).
pipe(terser({
output: {
ascii_only: true,
},
})).
pipe(concat('admin.min.js')).
pipe(gulp.dest('./src/main/resources/js/admin'))
}
function miniAdminLibs () {
// concat js
const jsJqueryUpload = [
'./src/main/resources/js/lib/jquery/jquery.min.js',
'./src/main/resources/js/lib/jquery/jquery.bowknot.min.js']
return gulp.src(jsJqueryUpload).
pipe(terser({
output: {
ascii_only: true,
},
})).
// https://github.com/b3log/solo/issues/12522
pipe(concat('admin-lib.min.js')).
pipe(gulp.dest('./src/main/resources/js/lib/compress/'))
}
function miniPjax () {
// concat js
const jsPjax = [
'./src/main/resources/js/lib/jquery/jquery-3.1.0.min.js',
'./src/main/resources/js/lib/jquery/jquery.pjax.js',
'./src/main/resources/js/lib/nprogress/nprogress.js']
return gulp.src(jsPjax).
pipe(terser({
output: {
ascii_only: true,
},
})).
pipe(concat('pjax.min.js')).
pipe(gulp.dest('./src/main/resources/js/lib/compress/'))
}
function minSkinJS () {
// minify js
return gulp.src('./src/main/resources/skins/*/js/*.js').
pipe(rename({suffix: '.min'})).
pipe(terser({
output: {
ascii_only: true,
},
})).
pipe(gulp.dest('./src/main/resources/skins/'))
}
function cleanProcess () {
return del([
'./src/main/resources/js/*.min.js',
'./src/main/resources/skins/*/js/*.min.js'])
}
gulp.task('default',
gulp.series(cleanProcess, sassSkinProcess, sassCommonProcess,
gulp.parallel(minSkinJS, minJS),
gulp.parallel(miniPjax, miniAdmin, miniAdminLibs)))